cpu.cc revision 2875
11689SN/A/*
22325SN/A * Copyright (c) 2004-2006 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
321858SN/A#include "config/full_system.hh"
332733Sktlim@umich.edu#include "config/use_checker.hh"
341858SN/A
351858SN/A#if FULL_SYSTEM
361060SN/A#include "sim/system.hh"
371060SN/A#else
381060SN/A#include "sim/process.hh"
391060SN/A#endif
401060SN/A
412325SN/A#include "cpu/activity.hh"
422683Sktlim@umich.edu#include "cpu/simple_thread.hh"
432680Sktlim@umich.edu#include "cpu/thread_context.hh"
442817Sksewell@umich.edu#include "cpu/o3/isa_specific.hh"
451717SN/A#include "cpu/o3/cpu.hh"
461060SN/A
472325SN/A#include "sim/root.hh"
482292SN/A#include "sim/stat_control.hh"
492292SN/A
502794Sktlim@umich.edu#if USE_CHECKER
512794Sktlim@umich.edu#include "cpu/checker/cpu.hh"
522794Sktlim@umich.edu#endif
532794Sktlim@umich.edu
541060SN/Ausing namespace std;
552669Sktlim@umich.eduusing namespace TheISA;
561060SN/A
572733Sktlim@umich.eduBaseO3CPU::BaseO3CPU(Params *params)
582292SN/A    : BaseCPU(params), cpu_id(0)
591060SN/A{
601060SN/A}
611060SN/A
622292SN/Avoid
632733Sktlim@umich.eduBaseO3CPU::regStats()
642292SN/A{
652292SN/A    BaseCPU::regStats();
662292SN/A}
672292SN/A
681060SN/Atemplate <class Impl>
691755SN/AFullO3CPU<Impl>::TickEvent::TickEvent(FullO3CPU<Impl> *c)
701060SN/A    : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c)
711060SN/A{
721060SN/A}
731060SN/A
741060SN/Atemplate <class Impl>
751060SN/Avoid
761755SN/AFullO3CPU<Impl>::TickEvent::process()
771060SN/A{
781060SN/A    cpu->tick();
791060SN/A}
801060SN/A
811060SN/Atemplate <class Impl>
821060SN/Aconst char *
831755SN/AFullO3CPU<Impl>::TickEvent::description()
841060SN/A{
851755SN/A    return "FullO3CPU tick event";
861060SN/A}
871060SN/A
881060SN/Atemplate <class Impl>
892829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::ActivateThreadEvent()
902829Sksewell@umich.edu    : Event(&mainEventQueue, CPU_Tick_Pri)
912829Sksewell@umich.edu{
922829Sksewell@umich.edu}
932829Sksewell@umich.edu
942829Sksewell@umich.edutemplate <class Impl>
952829Sksewell@umich.eduvoid
962829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::init(int thread_num,
972829Sksewell@umich.edu                                           FullO3CPU<Impl> *thread_cpu)
982829Sksewell@umich.edu{
992829Sksewell@umich.edu    tid = thread_num;
1002829Sksewell@umich.edu    cpu = thread_cpu;
1012829Sksewell@umich.edu}
1022829Sksewell@umich.edu
1032829Sksewell@umich.edutemplate <class Impl>
1042829Sksewell@umich.eduvoid
1052829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::process()
1062829Sksewell@umich.edu{
1072829Sksewell@umich.edu    cpu->activateThread(tid);
1082829Sksewell@umich.edu}
1092829Sksewell@umich.edu
1102829Sksewell@umich.edutemplate <class Impl>
1112829Sksewell@umich.educonst char *
1122829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::description()
1132829Sksewell@umich.edu{
1142829Sksewell@umich.edu    return "FullO3CPU \"Activate Thread\" event";
1152829Sksewell@umich.edu}
1162829Sksewell@umich.edu
1172829Sksewell@umich.edutemplate <class Impl>
1182875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::DeallocateContextEvent()
1192875Sksewell@umich.edu    : Event(&mainEventQueue, CPU_Tick_Pri)
1202875Sksewell@umich.edu{
1212875Sksewell@umich.edu}
1222875Sksewell@umich.edu
1232875Sksewell@umich.edutemplate <class Impl>
1242875Sksewell@umich.eduvoid
1252875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::init(int thread_num,
1262875Sksewell@umich.edu                                           FullO3CPU<Impl> *thread_cpu)
1272875Sksewell@umich.edu{
1282875Sksewell@umich.edu    tid = thread_num;
1292875Sksewell@umich.edu    cpu = thread_cpu;
1302875Sksewell@umich.edu}
1312875Sksewell@umich.edu
1322875Sksewell@umich.edutemplate <class Impl>
1332875Sksewell@umich.eduvoid
1342875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::process()
1352875Sksewell@umich.edu{
1362875Sksewell@umich.edu    cpu->deactivateThread(tid);
1372875Sksewell@umich.edu    cpu->removeThread(tid);
1382875Sksewell@umich.edu}
1392875Sksewell@umich.edu
1402875Sksewell@umich.edutemplate <class Impl>
1412875Sksewell@umich.educonst char *
1422875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::description()
1432875Sksewell@umich.edu{
1442875Sksewell@umich.edu    return "FullO3CPU \"Deallocate Context\" event";
1452875Sksewell@umich.edu}
1462875Sksewell@umich.edu
1472875Sksewell@umich.edutemplate <class Impl>
1482292SN/AFullO3CPU<Impl>::FullO3CPU(Params *params)
1492733Sktlim@umich.edu    : BaseO3CPU(params),
1501060SN/A      tickEvent(this),
1512292SN/A      removeInstsThisCycle(false),
1521060SN/A      fetch(params),
1531060SN/A      decode(params),
1541060SN/A      rename(params),
1551060SN/A      iew(params),
1561060SN/A      commit(params),
1571060SN/A
1582292SN/A      regFile(params->numPhysIntRegs, params->numPhysFloatRegs),
1591060SN/A
1602831Sksewell@umich.edu      freeList(params->numberOfThreads,
1612292SN/A               TheISA::NumIntRegs, params->numPhysIntRegs,
1622292SN/A               TheISA::NumFloatRegs, params->numPhysFloatRegs),
1631060SN/A
1642292SN/A      rob(params->numROBEntries, params->squashWidth,
1652292SN/A          params->smtROBPolicy, params->smtROBThreshold,
1662292SN/A          params->numberOfThreads),
1671060SN/A
1682831Sksewell@umich.edu      scoreboard(params->numberOfThreads,
1692292SN/A                 TheISA::NumIntRegs, params->numPhysIntRegs,
1702292SN/A                 TheISA::NumFloatRegs, params->numPhysFloatRegs,
1712292SN/A                 TheISA::NumMiscRegs * number_of_threads,
1722292SN/A                 TheISA::ZeroReg),
1731060SN/A
1741060SN/A      // For now just have these time buffers be pretty big.
1752325SN/A      // @todo: Make these time buffer sizes parameters or derived
1762325SN/A      // from latencies
1771061SN/A      timeBuffer(5, 5),
1781061SN/A      fetchQueue(5, 5),
1791061SN/A      decodeQueue(5, 5),
1801061SN/A      renameQueue(5, 5),
1811061SN/A      iewQueue(5, 5),
1822325SN/A      activityRec(NumStages, 10, params->activity),
1831060SN/A
1841060SN/A      globalSeqNum(1),
1851060SN/A
1861858SN/A#if FULL_SYSTEM
1872292SN/A      system(params->system),
1881060SN/A      physmem(system->physmem),
1891060SN/A#endif // FULL_SYSTEM
1902292SN/A      mem(params->mem),
1912316SN/A      switchCount(0),
1922316SN/A      deferRegistration(params->deferRegistration),
1932316SN/A      numThreads(number_of_threads)
1941060SN/A{
1951060SN/A    _status = Idle;
1961681SN/A
1972733Sktlim@umich.edu    checker = NULL;
1982733Sktlim@umich.edu
1992794Sktlim@umich.edu    if (params->checker) {
2002733Sktlim@umich.edu#if USE_CHECKER
2012316SN/A        BaseCPU *temp_checker = params->checker;
2022316SN/A        checker = dynamic_cast<Checker<DynInstPtr> *>(temp_checker);
2032316SN/A        checker->setMemory(mem);
2042316SN/A#if FULL_SYSTEM
2052316SN/A        checker->setSystem(params->system);
2062316SN/A#endif
2072794Sktlim@umich.edu#else
2082794Sktlim@umich.edu        panic("Checker enabled but not compiled in!");
2092794Sktlim@umich.edu#endif // USE_CHECKER
2102316SN/A    }
2112316SN/A
2121858SN/A#if !FULL_SYSTEM
2132292SN/A    thread.resize(number_of_threads);
2142292SN/A    tids.resize(number_of_threads);
2151681SN/A#endif
2161681SN/A
2172325SN/A    // The stages also need their CPU pointer setup.  However this
2182325SN/A    // must be done at the upper level CPU because they have pointers
2192325SN/A    // to the upper level CPU, and not this FullO3CPU.
2201060SN/A
2212292SN/A    // Set up Pointers to the activeThreads list for each stage
2222292SN/A    fetch.setActiveThreads(&activeThreads);
2232292SN/A    decode.setActiveThreads(&activeThreads);
2242292SN/A    rename.setActiveThreads(&activeThreads);
2252292SN/A    iew.setActiveThreads(&activeThreads);
2262292SN/A    commit.setActiveThreads(&activeThreads);
2271060SN/A
2281060SN/A    // Give each of the stages the time buffer they will use.
2291060SN/A    fetch.setTimeBuffer(&timeBuffer);
2301060SN/A    decode.setTimeBuffer(&timeBuffer);
2311060SN/A    rename.setTimeBuffer(&timeBuffer);
2321060SN/A    iew.setTimeBuffer(&timeBuffer);
2331060SN/A    commit.setTimeBuffer(&timeBuffer);
2341060SN/A
2351060SN/A    // Also setup each of the stages' queues.
2361060SN/A    fetch.setFetchQueue(&fetchQueue);
2371060SN/A    decode.setFetchQueue(&fetchQueue);
2382292SN/A    commit.setFetchQueue(&fetchQueue);
2391060SN/A    decode.setDecodeQueue(&decodeQueue);
2401060SN/A    rename.setDecodeQueue(&decodeQueue);
2411060SN/A    rename.setRenameQueue(&renameQueue);
2421060SN/A    iew.setRenameQueue(&renameQueue);
2431060SN/A    iew.setIEWQueue(&iewQueue);
2441060SN/A    commit.setIEWQueue(&iewQueue);
2451060SN/A    commit.setRenameQueue(&renameQueue);
2461060SN/A
2472316SN/A    commit.setFetchStage(&fetch);
2482292SN/A    commit.setIEWStage(&iew);
2492292SN/A    rename.setIEWStage(&iew);
2502292SN/A    rename.setCommitStage(&commit);
2512292SN/A
2522292SN/A#if !FULL_SYSTEM
2532307SN/A    int active_threads = params->workload.size();
2542831Sksewell@umich.edu
2552831Sksewell@umich.edu    if (active_threads > Impl::MaxThreads) {
2562831Sksewell@umich.edu        panic("Workload Size too large. Increase the 'MaxThreads'"
2572831Sksewell@umich.edu              "constant in your O3CPU impl. file (e.g. o3/alpha/impl.hh) or "
2582831Sksewell@umich.edu              "edit your workload size.");
2592831Sksewell@umich.edu    }
2602292SN/A#else
2612307SN/A    int active_threads = 1;
2622292SN/A#endif
2632292SN/A
2642316SN/A    //Make Sure That this a Valid Architeture
2652292SN/A    assert(params->numPhysIntRegs   >= numThreads * TheISA::NumIntRegs);
2662292SN/A    assert(params->numPhysFloatRegs >= numThreads * TheISA::NumFloatRegs);
2672292SN/A
2682292SN/A    rename.setScoreboard(&scoreboard);
2692292SN/A    iew.setScoreboard(&scoreboard);
2702292SN/A
2711060SN/A    // Setup the rename map for whichever stages need it.
2722292SN/A    PhysRegIndex lreg_idx = 0;
2732292SN/A    PhysRegIndex freg_idx = params->numPhysIntRegs; //Index to 1 after int regs
2741060SN/A
2752292SN/A    for (int tid=0; tid < numThreads; tid++) {
2762307SN/A        bool bindRegs = (tid <= active_threads - 1);
2772292SN/A
2782292SN/A        commitRenameMap[tid].init(TheISA::NumIntRegs,
2792292SN/A                                  params->numPhysIntRegs,
2802325SN/A                                  lreg_idx,            //Index for Logical. Regs
2812292SN/A
2822292SN/A                                  TheISA::NumFloatRegs,
2832292SN/A                                  params->numPhysFloatRegs,
2842325SN/A                                  freg_idx,            //Index for Float Regs
2852292SN/A
2862292SN/A                                  TheISA::NumMiscRegs,
2872292SN/A
2882292SN/A                                  TheISA::ZeroReg,
2892292SN/A                                  TheISA::ZeroReg,
2902292SN/A
2912292SN/A                                  tid,
2922292SN/A                                  false);
2932292SN/A
2942292SN/A        renameMap[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                            bindRegs);
3092292SN/A    }
3102292SN/A
3112292SN/A    rename.setRenameMap(renameMap);
3122292SN/A    commit.setRenameMap(commitRenameMap);
3132292SN/A
3142292SN/A    // Give renameMap & rename stage access to the freeList;
3152292SN/A    for (int i=0; i < numThreads; i++) {
3162292SN/A        renameMap[i].setFreeList(&freeList);
3172292SN/A    }
3181060SN/A    rename.setFreeList(&freeList);
3192292SN/A
3201060SN/A    // Setup the ROB for whichever stages need it.
3211060SN/A    commit.setROB(&rob);
3222292SN/A
3232292SN/A    lastRunningCycle = curTick;
3242292SN/A
3252829Sksewell@umich.edu    lastActivatedCycle = -1;
3262829Sksewell@umich.edu
3272292SN/A    contextSwitch = false;
3281060SN/A}
3291060SN/A
3301060SN/Atemplate <class Impl>
3311755SN/AFullO3CPU<Impl>::~FullO3CPU()
3321060SN/A{
3331060SN/A}
3341060SN/A
3351060SN/Atemplate <class Impl>
3361060SN/Avoid
3371755SN/AFullO3CPU<Impl>::fullCPURegStats()
3381062SN/A{
3392733Sktlim@umich.edu    BaseO3CPU::regStats();
3402292SN/A
3412733Sktlim@umich.edu    // Register any of the O3CPU's stats here.
3422292SN/A    timesIdled
3432292SN/A        .name(name() + ".timesIdled")
3442292SN/A        .desc("Number of times that the entire CPU went into an idle state and"
3452292SN/A              " unscheduled itself")
3462292SN/A        .prereq(timesIdled);
3472292SN/A
3482292SN/A    idleCycles
3492292SN/A        .name(name() + ".idleCycles")
3502292SN/A        .desc("Total number of cycles that the CPU has spent unscheduled due "
3512292SN/A              "to idling")
3522292SN/A        .prereq(idleCycles);
3532292SN/A
3542292SN/A    // Number of Instructions simulated
3552292SN/A    // --------------------------------
3562292SN/A    // Should probably be in Base CPU but need templated
3572292SN/A    // MaxThreads so put in here instead
3582292SN/A    committedInsts
3592292SN/A        .init(numThreads)
3602292SN/A        .name(name() + ".committedInsts")
3612292SN/A        .desc("Number of Instructions Simulated");
3622292SN/A
3632292SN/A    totalCommittedInsts
3642292SN/A        .name(name() + ".committedInsts_total")
3652292SN/A        .desc("Number of Instructions Simulated");
3662292SN/A
3672292SN/A    cpi
3682292SN/A        .name(name() + ".cpi")
3692292SN/A        .desc("CPI: Cycles Per Instruction")
3702292SN/A        .precision(6);
3712292SN/A    cpi = simTicks / committedInsts;
3722292SN/A
3732292SN/A    totalCpi
3742292SN/A        .name(name() + ".cpi_total")
3752292SN/A        .desc("CPI: Total CPI of All Threads")
3762292SN/A        .precision(6);
3772292SN/A    totalCpi = simTicks / totalCommittedInsts;
3782292SN/A
3792292SN/A    ipc
3802292SN/A        .name(name() + ".ipc")
3812292SN/A        .desc("IPC: Instructions Per Cycle")
3822292SN/A        .precision(6);
3832292SN/A    ipc =  committedInsts / simTicks;
3842292SN/A
3852292SN/A    totalIpc
3862292SN/A        .name(name() + ".ipc_total")
3872292SN/A        .desc("IPC: Total IPC of All Threads")
3882292SN/A        .precision(6);
3892292SN/A    totalIpc =  totalCommittedInsts / simTicks;
3902292SN/A
3911062SN/A}
3921062SN/A
3931062SN/Atemplate <class Impl>
3941062SN/Avoid
3951755SN/AFullO3CPU<Impl>::tick()
3961060SN/A{
3972733Sktlim@umich.edu    DPRINTF(O3CPU, "\n\nFullO3CPU: Ticking main, FullO3CPU.\n");
3981060SN/A
3992292SN/A    ++numCycles;
4002292SN/A
4012325SN/A//    activity = false;
4022292SN/A
4032292SN/A    //Tick each of the stages
4041060SN/A    fetch.tick();
4051060SN/A
4061060SN/A    decode.tick();
4071060SN/A
4081060SN/A    rename.tick();
4091060SN/A
4101060SN/A    iew.tick();
4111060SN/A
4121060SN/A    commit.tick();
4131060SN/A
4142292SN/A#if !FULL_SYSTEM
4152292SN/A    doContextSwitch();
4162292SN/A#endif
4172292SN/A
4182292SN/A    // Now advance the time buffers
4191060SN/A    timeBuffer.advance();
4201060SN/A
4211060SN/A    fetchQueue.advance();
4221060SN/A    decodeQueue.advance();
4231060SN/A    renameQueue.advance();
4241060SN/A    iewQueue.advance();
4251060SN/A
4262325SN/A    activityRec.advance();
4272292SN/A
4282292SN/A    if (removeInstsThisCycle) {
4292292SN/A        cleanUpRemovedInsts();
4302292SN/A    }
4312292SN/A
4322325SN/A    if (!tickEvent.scheduled()) {
4332325SN/A        if (_status == SwitchedOut) {
4342325SN/A            // increment stat
4352325SN/A            lastRunningCycle = curTick;
4362325SN/A        } else if (!activityRec.active()) {
4372325SN/A            lastRunningCycle = curTick;
4382325SN/A            timesIdled++;
4392325SN/A        } else {
4402325SN/A            tickEvent.schedule(curTick + cycles(1));
4412325SN/A        }
4422292SN/A    }
4432292SN/A
4442292SN/A#if !FULL_SYSTEM
4452292SN/A    updateThreadPriority();
4462292SN/A#endif
4472292SN/A
4481060SN/A}
4491060SN/A
4501060SN/Atemplate <class Impl>
4511060SN/Avoid
4521755SN/AFullO3CPU<Impl>::init()
4531060SN/A{
4542307SN/A    if (!deferRegistration) {
4552680Sktlim@umich.edu        registerThreadContexts();
4562292SN/A    }
4571060SN/A
4582292SN/A    // Set inSyscall so that the CPU doesn't squash when initially
4592292SN/A    // setting up registers.
4602292SN/A    for (int i = 0; i < number_of_threads; ++i)
4612292SN/A        thread[i]->inSyscall = true;
4622292SN/A
4632292SN/A    for (int tid=0; tid < number_of_threads; tid++) {
4641858SN/A#if FULL_SYSTEM
4652680Sktlim@umich.edu        ThreadContext *src_tc = threadContexts[tid];
4661681SN/A#else
4672680Sktlim@umich.edu        ThreadContext *src_tc = thread[tid]->getTC();
4681681SN/A#endif
4692292SN/A        // Threads start in the Suspended State
4702680Sktlim@umich.edu        if (src_tc->status() != ThreadContext::Suspended) {
4712292SN/A            continue;
4721060SN/A        }
4731060SN/A
4742292SN/A#if FULL_SYSTEM
4752680Sktlim@umich.edu        TheISA::initCPU(src_tc, src_tc->readCpuId());
4762292SN/A#endif
4772292SN/A    }
4782292SN/A
4792292SN/A    // Clear inSyscall.
4802292SN/A    for (int i = 0; i < number_of_threads; ++i)
4812292SN/A        thread[i]->inSyscall = false;
4822292SN/A
4832316SN/A    // Initialize stages.
4842292SN/A    fetch.initStage();
4852292SN/A    iew.initStage();
4862292SN/A    rename.initStage();
4872292SN/A    commit.initStage();
4882292SN/A
4892292SN/A    commit.setThreads(thread);
4902292SN/A}
4912292SN/A
4922292SN/Atemplate <class Impl>
4932292SN/Avoid
4942875Sksewell@umich.eduFullO3CPU<Impl>::activateThread(unsigned tid)
4952875Sksewell@umich.edu{
4962875Sksewell@umich.edu    list<unsigned>::iterator isActive = find(
4972875Sksewell@umich.edu        activeThreads.begin(), activeThreads.end(), tid);
4982875Sksewell@umich.edu
4992875Sksewell@umich.edu    if (isActive == activeThreads.end()) {
5002875Sksewell@umich.edu        DPRINTF(O3CPU, "[tid:%i]: Adding to active threads list\n",
5012875Sksewell@umich.edu                tid);
5022875Sksewell@umich.edu
5032875Sksewell@umich.edu        activeThreads.push_back(tid);
5042875Sksewell@umich.edu    }
5052875Sksewell@umich.edu}
5062875Sksewell@umich.edu
5072875Sksewell@umich.edutemplate <class Impl>
5082875Sksewell@umich.eduvoid
5092875Sksewell@umich.eduFullO3CPU<Impl>::deactivateThread(unsigned tid)
5102875Sksewell@umich.edu{
5112875Sksewell@umich.edu    //Remove From Active List, if Active
5122875Sksewell@umich.edu    list<unsigned>::iterator thread_it =
5132875Sksewell@umich.edu        find(activeThreads.begin(), activeThreads.end(), tid);
5142875Sksewell@umich.edu
5152875Sksewell@umich.edu    if (thread_it != activeThreads.end()) {
5162875Sksewell@umich.edu        DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n",
5172875Sksewell@umich.edu                tid);
5182875Sksewell@umich.edu        activeThreads.erase(thread_it);
5192875Sksewell@umich.edu    }
5202875Sksewell@umich.edu}
5212875Sksewell@umich.edu
5222875Sksewell@umich.edutemplate <class Impl>
5232875Sksewell@umich.eduvoid
5242875Sksewell@umich.eduFullO3CPU<Impl>::activateContext(int tid, int delay)
5252875Sksewell@umich.edu{
5262875Sksewell@umich.edu    // Needs to set each stage to running as well.
5272875Sksewell@umich.edu    if (delay){
5282875Sksewell@umich.edu        DPRINTF(O3CPU, "[tid:%i]: Scheduling thread context to activate "
5292875Sksewell@umich.edu                "on cycle %d\n", tid, curTick + cycles(delay));
5302875Sksewell@umich.edu        scheduleActivateThreadEvent(tid, delay);
5312875Sksewell@umich.edu    } else {
5322875Sksewell@umich.edu        activateThread(tid);
5332875Sksewell@umich.edu    }
5342875Sksewell@umich.edu
5352875Sksewell@umich.edu    if(lastActivatedCycle < curTick) {
5362875Sksewell@umich.edu        scheduleTickEvent(delay);
5372875Sksewell@umich.edu
5382875Sksewell@umich.edu        // Be sure to signal that there's some activity so the CPU doesn't
5392875Sksewell@umich.edu        // deschedule itself.
5402875Sksewell@umich.edu        activityRec.activity();
5412875Sksewell@umich.edu        fetch.wakeFromQuiesce();
5422875Sksewell@umich.edu
5432875Sksewell@umich.edu        lastActivatedCycle = curTick;
5442875Sksewell@umich.edu
5452875Sksewell@umich.edu        _status = Running;
5462875Sksewell@umich.edu    }
5472875Sksewell@umich.edu}
5482875Sksewell@umich.edu
5492875Sksewell@umich.edutemplate <class Impl>
5502875Sksewell@umich.eduvoid
5512875Sksewell@umich.eduFullO3CPU<Impl>::deallocateContext(int tid, int delay)
5522875Sksewell@umich.edu{
5532875Sksewell@umich.edu    // Schedule removal of thread data from CPU
5542875Sksewell@umich.edu    if (delay){
5552875Sksewell@umich.edu        DPRINTF(O3CPU, "[tid:%i]: Scheduling thread context to deallocate "
5562875Sksewell@umich.edu                "on cycle %d\n", tid, curTick + cycles(delay));
5572875Sksewell@umich.edu        scheduleDeallocateContextEvent(tid, delay);
5582875Sksewell@umich.edu    } else {
5592875Sksewell@umich.edu        deactivateThread(tid);
5602875Sksewell@umich.edu        removeThread(tid);
5612875Sksewell@umich.edu    }
5622875Sksewell@umich.edu}
5632875Sksewell@umich.edu
5642875Sksewell@umich.edutemplate <class Impl>
5652875Sksewell@umich.eduvoid
5662875Sksewell@umich.eduFullO3CPU<Impl>::suspendContext(int tid)
5672875Sksewell@umich.edu{
5682875Sksewell@umich.edu    DPRINTF(O3CPU,"[tid: %i]: Suspending Thread Context.\n", tid);
5692875Sksewell@umich.edu    unscheduleTickEvent();
5702875Sksewell@umich.edu    _status = Idle;
5712875Sksewell@umich.edu/*
5722875Sksewell@umich.edu    //Remove From Active List, if Active
5732875Sksewell@umich.edu    list<unsigned>::iterator isActive = find(
5742875Sksewell@umich.edu        activeThreads.begin(), activeThreads.end(), tid);
5752875Sksewell@umich.edu
5762875Sksewell@umich.edu    if (isActive != activeThreads.end()) {
5772875Sksewell@umich.edu        DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n",
5782875Sksewell@umich.edu                tid);
5792875Sksewell@umich.edu        activeThreads.erase(isActive);
5802875Sksewell@umich.edu    }
5812875Sksewell@umich.edu*/
5822875Sksewell@umich.edu}
5832875Sksewell@umich.edu
5842875Sksewell@umich.edutemplate <class Impl>
5852875Sksewell@umich.eduvoid
5862875Sksewell@umich.eduFullO3CPU<Impl>::haltContext(int tid)
5872875Sksewell@umich.edu{
5882875Sksewell@umich.edu    DPRINTF(O3CPU,"[tid:%i]: Halting Thread Context", tid);
5892875Sksewell@umich.edu/*
5902875Sksewell@umich.edu    //Remove From Active List, if Active
5912875Sksewell@umich.edu    list<unsigned>::iterator isActive = find(
5922875Sksewell@umich.edu        activeThreads.begin(), activeThreads.end(), tid);
5932875Sksewell@umich.edu
5942875Sksewell@umich.edu    if (isActive != activeThreads.end()) {
5952875Sksewell@umich.edu        DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n",
5962875Sksewell@umich.edu                tid);
5972875Sksewell@umich.edu        activeThreads.erase(isActive);
5982875Sksewell@umich.edu
5992875Sksewell@umich.edu        removeThread(tid);
6002875Sksewell@umich.edu    }
6012875Sksewell@umich.edu*/
6022875Sksewell@umich.edu}
6032875Sksewell@umich.edu
6042875Sksewell@umich.edutemplate <class Impl>
6052875Sksewell@umich.eduvoid
6062292SN/AFullO3CPU<Impl>::insertThread(unsigned tid)
6072292SN/A{
6082847Sksewell@umich.edu    DPRINTF(O3CPU,"[tid:%i] Initializing thread into CPU");
6092292SN/A    // Will change now that the PC and thread state is internal to the CPU
6102683Sktlim@umich.edu    // and not in the ThreadContext.
6112292SN/A#if FULL_SYSTEM
6122680Sktlim@umich.edu    ThreadContext *src_tc = system->threadContexts[tid];
6132292SN/A#else
6142847Sksewell@umich.edu    ThreadContext *src_tc = tcBase(tid);
6152292SN/A#endif
6162292SN/A
6172292SN/A    //Bind Int Regs to Rename Map
6182292SN/A    for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) {
6192292SN/A        PhysRegIndex phys_reg = freeList.getIntReg();
6202292SN/A
6212292SN/A        renameMap[tid].setEntry(ireg,phys_reg);
6222292SN/A        scoreboard.setReg(phys_reg);
6232292SN/A    }
6242292SN/A
6252292SN/A    //Bind Float Regs to Rename Map
6262292SN/A    for (int freg = 0; freg < TheISA::NumFloatRegs; freg++) {
6272292SN/A        PhysRegIndex phys_reg = freeList.getFloatReg();
6282292SN/A
6292292SN/A        renameMap[tid].setEntry(freg,phys_reg);
6302292SN/A        scoreboard.setReg(phys_reg);
6312292SN/A    }
6322292SN/A
6332292SN/A    //Copy Thread Data Into RegFile
6342847Sksewell@umich.edu    //this->copyFromTC(tid);
6352292SN/A
6362847Sksewell@umich.edu    //Set PC/NPC/NNPC
6372847Sksewell@umich.edu    setPC(src_tc->readPC(), tid);
6382847Sksewell@umich.edu    setNextPC(src_tc->readNextPC(), tid);
6392847Sksewell@umich.edu#if THE_ISA != ALPHA_ISA
6402847Sksewell@umich.edu    setNextNPC(src_tc->readNextNPC(), tid);
6412847Sksewell@umich.edu#endif
6422292SN/A
6432680Sktlim@umich.edu    src_tc->setStatus(ThreadContext::Active);
6442292SN/A
6452292SN/A    activateContext(tid,1);
6462292SN/A
6472292SN/A    //Reset ROB/IQ/LSQ Entries
6482292SN/A    commit.rob->resetEntries();
6492292SN/A    iew.resetEntries();
6502292SN/A}
6512292SN/A
6522292SN/Atemplate <class Impl>
6532292SN/Avoid
6542292SN/AFullO3CPU<Impl>::removeThread(unsigned tid)
6552292SN/A{
6562875Sksewell@umich.edu    DPRINTF(O3CPU,"[tid:%i] Removing thread context from CPU.");
6572847Sksewell@umich.edu
6582847Sksewell@umich.edu    // Copy Thread Data From RegFile
6592847Sksewell@umich.edu    // If thread is suspended, it might be re-allocated
6602847Sksewell@umich.edu    //this->copyToTC(tid);
6612847Sksewell@umich.edu
6622847Sksewell@umich.edu    // Unbind Int Regs from Rename Map
6632292SN/A    for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) {
6642292SN/A        PhysRegIndex phys_reg = renameMap[tid].lookup(ireg);
6652292SN/A
6662292SN/A        scoreboard.unsetReg(phys_reg);
6672292SN/A        freeList.addReg(phys_reg);
6682292SN/A    }
6692292SN/A
6702847Sksewell@umich.edu    // Unbind Float Regs from Rename Map
6712292SN/A    for (int freg = 0; freg < TheISA::NumFloatRegs; freg++) {
6722292SN/A        PhysRegIndex phys_reg = renameMap[tid].lookup(freg);
6732292SN/A
6742292SN/A        scoreboard.unsetReg(phys_reg);
6752292SN/A        freeList.addReg(phys_reg);
6762292SN/A    }
6772292SN/A
6782847Sksewell@umich.edu    // Squash Throughout Pipeline
6792292SN/A    fetch.squash(0,tid);
6802292SN/A    decode.squash(tid);
6812292SN/A    rename.squash(tid);
6822875Sksewell@umich.edu    iew.squash(tid);
6832875Sksewell@umich.edu    commit.rob->squash(commit.rob->readHeadInst(tid)->seqNum, tid);
6842292SN/A
6852292SN/A    assert(iew.ldstQueue.getCount(tid) == 0);
6862292SN/A
6872847Sksewell@umich.edu    // Reset ROB/IQ/LSQ Entries
6882292SN/A    if (activeThreads.size() >= 1) {
6892292SN/A        commit.rob->resetEntries();
6902292SN/A        iew.resetEntries();
6912292SN/A    }
6922292SN/A}
6932292SN/A
6942292SN/A
6952292SN/Atemplate <class Impl>
6962292SN/Avoid
6972292SN/AFullO3CPU<Impl>::activateWhenReady(int tid)
6982292SN/A{
6992733Sktlim@umich.edu    DPRINTF(O3CPU,"[tid:%i]: Checking if resources are available for incoming"
7002292SN/A            "(e.g. PhysRegs/ROB/IQ/LSQ) \n",
7012292SN/A            tid);
7022292SN/A
7032292SN/A    bool ready = true;
7042292SN/A
7052292SN/A    if (freeList.numFreeIntRegs() >= TheISA::NumIntRegs) {
7062733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
7072292SN/A                "Phys. Int. Regs.\n",
7082292SN/A                tid);
7092292SN/A        ready = false;
7102292SN/A    } else if (freeList.numFreeFloatRegs() >= TheISA::NumFloatRegs) {
7112733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
7122292SN/A                "Phys. Float. Regs.\n",
7132292SN/A                tid);
7142292SN/A        ready = false;
7152292SN/A    } else if (commit.rob->numFreeEntries() >=
7162292SN/A               commit.rob->entryAmount(activeThreads.size() + 1)) {
7172733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
7182292SN/A                "ROB entries.\n",
7192292SN/A                tid);
7202292SN/A        ready = false;
7212292SN/A    } else if (iew.instQueue.numFreeEntries() >=
7222292SN/A               iew.instQueue.entryAmount(activeThreads.size() + 1)) {
7232733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
7242292SN/A                "IQ entries.\n",
7252292SN/A                tid);
7262292SN/A        ready = false;
7272292SN/A    } else if (iew.ldstQueue.numFreeEntries() >=
7282292SN/A               iew.ldstQueue.entryAmount(activeThreads.size() + 1)) {
7292733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
7302292SN/A                "LSQ entries.\n",
7312292SN/A                tid);
7322292SN/A        ready = false;
7332292SN/A    }
7342292SN/A
7352292SN/A    if (ready) {
7362292SN/A        insertThread(tid);
7372292SN/A
7382292SN/A        contextSwitch = false;
7392292SN/A
7402292SN/A        cpuWaitList.remove(tid);
7412292SN/A    } else {
7422292SN/A        suspendContext(tid);
7432292SN/A
7442292SN/A        //blocks fetch
7452292SN/A        contextSwitch = true;
7462292SN/A
7472875Sksewell@umich.edu        //@todo: dont always add to waitlist
7482292SN/A        //do waitlist
7492292SN/A        cpuWaitList.push_back(tid);
7501060SN/A    }
7511060SN/A}
7521060SN/A
7531060SN/Atemplate <class Impl>
7541060SN/Avoid
7552840Sktlim@umich.eduFullO3CPU<Impl>::switchOut()
7561060SN/A{
7572316SN/A    switchCount = 0;
7582307SN/A    fetch.switchOut();
7592307SN/A    decode.switchOut();
7602307SN/A    rename.switchOut();
7612307SN/A    iew.switchOut();
7622307SN/A    commit.switchOut();
7632325SN/A
7642325SN/A    // Wake the CPU and record activity so everything can drain out if
7652325SN/A    // the CPU is currently idle.
7662325SN/A    wakeCPU();
7672325SN/A    activityRec.activity();
7682316SN/A}
7692310SN/A
7702316SN/Atemplate <class Impl>
7712316SN/Avoid
7722316SN/AFullO3CPU<Impl>::signalSwitched()
7732316SN/A{
7742325SN/A    if (++switchCount == NumStages) {
7752316SN/A        fetch.doSwitchOut();
7762316SN/A        rename.doSwitchOut();
7772316SN/A        commit.doSwitchOut();
7782316SN/A        instList.clear();
7792316SN/A        while (!removeList.empty()) {
7802316SN/A            removeList.pop();
7812316SN/A        }
7822316SN/A
7832794Sktlim@umich.edu#if USE_CHECKER
7842316SN/A        if (checker)
7852840Sktlim@umich.edu            checker->switchOut();
7862794Sktlim@umich.edu#endif
7872316SN/A
7882316SN/A        if (tickEvent.scheduled())
7892316SN/A            tickEvent.squash();
7902316SN/A        _status = SwitchedOut;
7912310SN/A    }
7922316SN/A    assert(switchCount <= 5);
7931060SN/A}
7941060SN/A
7951060SN/Atemplate <class Impl>
7961060SN/Avoid
7971755SN/AFullO3CPU<Impl>::takeOverFrom(BaseCPU *oldCPU)
7981060SN/A{
7992325SN/A    // Flush out any old data from the time buffers.
8002325SN/A    for (int i = 0; i < 10; ++i) {
8012307SN/A        timeBuffer.advance();
8022307SN/A        fetchQueue.advance();
8032307SN/A        decodeQueue.advance();
8042307SN/A        renameQueue.advance();
8052307SN/A        iewQueue.advance();
8062307SN/A    }
8072307SN/A
8082325SN/A    activityRec.reset();
8092307SN/A
8101060SN/A    BaseCPU::takeOverFrom(oldCPU);
8111060SN/A
8122307SN/A    fetch.takeOverFrom();
8132307SN/A    decode.takeOverFrom();
8142307SN/A    rename.takeOverFrom();
8152307SN/A    iew.takeOverFrom();
8162307SN/A    commit.takeOverFrom();
8172307SN/A
8181060SN/A    assert(!tickEvent.scheduled());
8191060SN/A
8202325SN/A    // @todo: Figure out how to properly select the tid to put onto
8212325SN/A    // the active threads list.
8222307SN/A    int tid = 0;
8232307SN/A
8242307SN/A    list<unsigned>::iterator isActive = find(
8252307SN/A        activeThreads.begin(), activeThreads.end(), tid);
8262307SN/A
8272307SN/A    if (isActive == activeThreads.end()) {
8282325SN/A        //May Need to Re-code this if the delay variable is the delay
8292325SN/A        //needed for thread to activate
8302733Sktlim@umich.edu        DPRINTF(O3CPU, "Adding Thread %i to active threads list\n",
8312307SN/A                tid);
8322307SN/A
8332307SN/A        activeThreads.push_back(tid);
8342307SN/A    }
8352307SN/A
8362325SN/A    // Set all statuses to active, schedule the CPU's tick event.
8372307SN/A    // @todo: Fix up statuses so this is handled properly
8382680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
8392680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
8402680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
8411681SN/A            _status = Running;
8421681SN/A            tickEvent.schedule(curTick);
8431681SN/A        }
8441060SN/A    }
8452307SN/A    if (!tickEvent.scheduled())
8462307SN/A        tickEvent.schedule(curTick);
8471060SN/A}
8481060SN/A
8491060SN/Atemplate <class Impl>
8501060SN/Auint64_t
8511755SN/AFullO3CPU<Impl>::readIntReg(int reg_idx)
8521060SN/A{
8531060SN/A    return regFile.readIntReg(reg_idx);
8541060SN/A}
8551060SN/A
8561060SN/Atemplate <class Impl>
8572455SN/AFloatReg
8582455SN/AFullO3CPU<Impl>::readFloatReg(int reg_idx, int width)
8591060SN/A{
8602455SN/A    return regFile.readFloatReg(reg_idx, width);
8611060SN/A}
8621060SN/A
8631060SN/Atemplate <class Impl>
8642455SN/AFloatReg
8652455SN/AFullO3CPU<Impl>::readFloatReg(int reg_idx)
8661060SN/A{
8672455SN/A    return regFile.readFloatReg(reg_idx);
8681060SN/A}
8691060SN/A
8701060SN/Atemplate <class Impl>
8712455SN/AFloatRegBits
8722455SN/AFullO3CPU<Impl>::readFloatRegBits(int reg_idx, int width)
8731060SN/A{
8742455SN/A    return regFile.readFloatRegBits(reg_idx, width);
8752455SN/A}
8762455SN/A
8772455SN/Atemplate <class Impl>
8782455SN/AFloatRegBits
8792455SN/AFullO3CPU<Impl>::readFloatRegBits(int reg_idx)
8802455SN/A{
8812455SN/A    return regFile.readFloatRegBits(reg_idx);
8821060SN/A}
8831060SN/A
8841060SN/Atemplate <class Impl>
8851060SN/Avoid
8861755SN/AFullO3CPU<Impl>::setIntReg(int reg_idx, uint64_t val)
8871060SN/A{
8881060SN/A    regFile.setIntReg(reg_idx, val);
8891060SN/A}
8901060SN/A
8911060SN/Atemplate <class Impl>
8921060SN/Avoid
8932455SN/AFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val, int width)
8941060SN/A{
8952455SN/A    regFile.setFloatReg(reg_idx, val, width);
8961060SN/A}
8971060SN/A
8981060SN/Atemplate <class Impl>
8991060SN/Avoid
9002455SN/AFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val)
9011060SN/A{
9022455SN/A    regFile.setFloatReg(reg_idx, val);
9031060SN/A}
9041060SN/A
9051060SN/Atemplate <class Impl>
9061060SN/Avoid
9072455SN/AFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val, int width)
9081060SN/A{
9092455SN/A    regFile.setFloatRegBits(reg_idx, val, width);
9102455SN/A}
9112455SN/A
9122455SN/Atemplate <class Impl>
9132455SN/Avoid
9142455SN/AFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
9152455SN/A{
9162455SN/A    regFile.setFloatRegBits(reg_idx, val);
9171060SN/A}
9181060SN/A
9191060SN/Atemplate <class Impl>
9201060SN/Auint64_t
9212292SN/AFullO3CPU<Impl>::readArchIntReg(int reg_idx, unsigned tid)
9221060SN/A{
9232292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
9242292SN/A
9252292SN/A    return regFile.readIntReg(phys_reg);
9262292SN/A}
9272292SN/A
9282292SN/Atemplate <class Impl>
9292292SN/Afloat
9302292SN/AFullO3CPU<Impl>::readArchFloatRegSingle(int reg_idx, unsigned tid)
9312292SN/A{
9322307SN/A    int idx = reg_idx + TheISA::FP_Base_DepTag;
9332307SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
9342292SN/A
9352669Sktlim@umich.edu    return regFile.readFloatReg(phys_reg);
9362292SN/A}
9372292SN/A
9382292SN/Atemplate <class Impl>
9392292SN/Adouble
9402292SN/AFullO3CPU<Impl>::readArchFloatRegDouble(int reg_idx, unsigned tid)
9412292SN/A{
9422307SN/A    int idx = reg_idx + TheISA::FP_Base_DepTag;
9432307SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
9442292SN/A
9452669Sktlim@umich.edu    return regFile.readFloatReg(phys_reg, 64);
9462292SN/A}
9472292SN/A
9482292SN/Atemplate <class Impl>
9492292SN/Auint64_t
9502292SN/AFullO3CPU<Impl>::readArchFloatRegInt(int reg_idx, unsigned tid)
9512292SN/A{
9522307SN/A    int idx = reg_idx + TheISA::FP_Base_DepTag;
9532307SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
9542292SN/A
9552669Sktlim@umich.edu    return regFile.readFloatRegBits(phys_reg);
9561060SN/A}
9571060SN/A
9581060SN/Atemplate <class Impl>
9591060SN/Avoid
9602292SN/AFullO3CPU<Impl>::setArchIntReg(int reg_idx, uint64_t val, unsigned tid)
9611060SN/A{
9622292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
9632292SN/A
9642292SN/A    regFile.setIntReg(phys_reg, val);
9651060SN/A}
9661060SN/A
9671060SN/Atemplate <class Impl>
9681060SN/Avoid
9692292SN/AFullO3CPU<Impl>::setArchFloatRegSingle(int reg_idx, float val, unsigned tid)
9701060SN/A{
9712292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
9722292SN/A
9732669Sktlim@umich.edu    regFile.setFloatReg(phys_reg, val);
9741060SN/A}
9751060SN/A
9761060SN/Atemplate <class Impl>
9771060SN/Avoid
9782292SN/AFullO3CPU<Impl>::setArchFloatRegDouble(int reg_idx, double val, unsigned tid)
9791060SN/A{
9802292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
9812292SN/A
9822669Sktlim@umich.edu    regFile.setFloatReg(phys_reg, val, 64);
9831060SN/A}
9841060SN/A
9851060SN/Atemplate <class Impl>
9861060SN/Avoid
9872292SN/AFullO3CPU<Impl>::setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid)
9881060SN/A{
9892292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
9901060SN/A
9912669Sktlim@umich.edu    regFile.setFloatRegBits(phys_reg, val);
9922292SN/A}
9932292SN/A
9942292SN/Atemplate <class Impl>
9952292SN/Auint64_t
9962292SN/AFullO3CPU<Impl>::readPC(unsigned tid)
9972292SN/A{
9982292SN/A    return commit.readPC(tid);
9991060SN/A}
10001060SN/A
10011060SN/Atemplate <class Impl>
10021060SN/Avoid
10032292SN/AFullO3CPU<Impl>::setPC(Addr new_PC,unsigned tid)
10041060SN/A{
10052292SN/A    commit.setPC(new_PC, tid);
10062292SN/A}
10071060SN/A
10082292SN/Atemplate <class Impl>
10092292SN/Auint64_t
10102292SN/AFullO3CPU<Impl>::readNextPC(unsigned tid)
10112292SN/A{
10122292SN/A    return commit.readNextPC(tid);
10132292SN/A}
10141060SN/A
10152292SN/Atemplate <class Impl>
10162292SN/Avoid
10172292SN/AFullO3CPU<Impl>::setNextPC(uint64_t val,unsigned tid)
10182292SN/A{
10192292SN/A    commit.setNextPC(val, tid);
10202292SN/A}
10211060SN/A
10222756Sksewell@umich.edu#if THE_ISA != ALPHA_ISA
10232756Sksewell@umich.edutemplate <class Impl>
10242756Sksewell@umich.eduuint64_t
10252756Sksewell@umich.eduFullO3CPU<Impl>::readNextNPC(unsigned tid)
10262756Sksewell@umich.edu{
10272756Sksewell@umich.edu    return commit.readNextNPC(tid);
10282756Sksewell@umich.edu}
10292756Sksewell@umich.edu
10302756Sksewell@umich.edutemplate <class Impl>
10312756Sksewell@umich.eduvoid
10322756Sksewell@umich.eduFullO3CPU<Impl>::setNextNNPC(uint64_t val,unsigned tid)
10332756Sksewell@umich.edu{
10342756Sksewell@umich.edu    commit.setNextNPC(val, tid);
10352756Sksewell@umich.edu}
10362756Sksewell@umich.edu#endif
10372756Sksewell@umich.edu
10382292SN/Atemplate <class Impl>
10392292SN/Atypename FullO3CPU<Impl>::ListIt
10402292SN/AFullO3CPU<Impl>::addInst(DynInstPtr &inst)
10412292SN/A{
10422292SN/A    instList.push_back(inst);
10431060SN/A
10442292SN/A    return --(instList.end());
10452292SN/A}
10461060SN/A
10472292SN/Atemplate <class Impl>
10482292SN/Avoid
10492292SN/AFullO3CPU<Impl>::instDone(unsigned tid)
10502292SN/A{
10512292SN/A    // Keep an instruction count.
10522292SN/A    thread[tid]->numInst++;
10532292SN/A    thread[tid]->numInsts++;
10542292SN/A    committedInsts[tid]++;
10552292SN/A    totalCommittedInsts++;
10562292SN/A
10572292SN/A    // Check for instruction-count-based events.
10582292SN/A    comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst);
10592292SN/A}
10602292SN/A
10612292SN/Atemplate <class Impl>
10622292SN/Avoid
10632292SN/AFullO3CPU<Impl>::addToRemoveList(DynInstPtr &inst)
10642292SN/A{
10652292SN/A    removeInstsThisCycle = true;
10662292SN/A
10672292SN/A    removeList.push(inst->getInstListIt());
10681060SN/A}
10691060SN/A
10701060SN/Atemplate <class Impl>
10711060SN/Avoid
10721755SN/AFullO3CPU<Impl>::removeFrontInst(DynInstPtr &inst)
10731060SN/A{
10742733Sktlim@umich.edu    DPRINTF(O3CPU, "Removing committed instruction [tid:%i] PC %#x "
10752292SN/A            "[sn:%lli]\n",
10762303SN/A            inst->threadNumber, inst->readPC(), inst->seqNum);
10771060SN/A
10782292SN/A    removeInstsThisCycle = true;
10791060SN/A
10801060SN/A    // Remove the front instruction.
10812292SN/A    removeList.push(inst->getInstListIt());
10821060SN/A}
10831060SN/A
10841060SN/Atemplate <class Impl>
10851060SN/Avoid
10862292SN/AFullO3CPU<Impl>::removeInstsNotInROB(unsigned tid)
10871060SN/A{
10882733Sktlim@umich.edu    DPRINTF(O3CPU, "Thread %i: Deleting instructions from instruction"
10892292SN/A            " list.\n", tid);
10901060SN/A
10912292SN/A    ListIt end_it;
10921060SN/A
10932292SN/A    bool rob_empty = false;
10942292SN/A
10952292SN/A    if (instList.empty()) {
10962292SN/A        return;
10972292SN/A    } else if (rob.isEmpty(/*tid*/)) {
10982733Sktlim@umich.edu        DPRINTF(O3CPU, "ROB is empty, squashing all insts.\n");
10992292SN/A        end_it = instList.begin();
11002292SN/A        rob_empty = true;
11012292SN/A    } else {
11022292SN/A        end_it = (rob.readTailInst(tid))->getInstListIt();
11032733Sktlim@umich.edu        DPRINTF(O3CPU, "ROB is not empty, squashing insts not in ROB.\n");
11042292SN/A    }
11052292SN/A
11062292SN/A    removeInstsThisCycle = true;
11072292SN/A
11082292SN/A    ListIt inst_it = instList.end();
11092292SN/A
11102292SN/A    inst_it--;
11112292SN/A
11122292SN/A    // Walk through the instruction list, removing any instructions
11132292SN/A    // that were inserted after the given instruction iterator, end_it.
11142292SN/A    while (inst_it != end_it) {
11152292SN/A        assert(!instList.empty());
11162292SN/A
11172292SN/A        squashInstIt(inst_it, tid);
11182292SN/A
11192292SN/A        inst_it--;
11202292SN/A    }
11212292SN/A
11222292SN/A    // If the ROB was empty, then we actually need to remove the first
11232292SN/A    // instruction as well.
11242292SN/A    if (rob_empty) {
11252292SN/A        squashInstIt(inst_it, tid);
11262292SN/A    }
11271060SN/A}
11281060SN/A
11291060SN/Atemplate <class Impl>
11301060SN/Avoid
11312292SN/AFullO3CPU<Impl>::removeInstsUntil(const InstSeqNum &seq_num,
11322292SN/A                                  unsigned tid)
11331062SN/A{
11342292SN/A    assert(!instList.empty());
11352292SN/A
11362292SN/A    removeInstsThisCycle = true;
11372292SN/A
11382292SN/A    ListIt inst_iter = instList.end();
11392292SN/A
11402292SN/A    inst_iter--;
11412292SN/A
11422733Sktlim@umich.edu    DPRINTF(O3CPU, "Deleting instructions from instruction "
11432292SN/A            "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
11442292SN/A            tid, seq_num, (*inst_iter)->seqNum);
11451062SN/A
11462292SN/A    while ((*inst_iter)->seqNum > seq_num) {
11471062SN/A
11482292SN/A        bool break_loop = (inst_iter == instList.begin());
11491062SN/A
11502292SN/A        squashInstIt(inst_iter, tid);
11511062SN/A
11522292SN/A        inst_iter--;
11531062SN/A
11542292SN/A        if (break_loop)
11552292SN/A            break;
11562292SN/A    }
11572292SN/A}
11582292SN/A
11592292SN/Atemplate <class Impl>
11602292SN/Ainline void
11612292SN/AFullO3CPU<Impl>::squashInstIt(const ListIt &instIt, const unsigned &tid)
11622292SN/A{
11632292SN/A    if ((*instIt)->threadNumber == tid) {
11642733Sktlim@umich.edu        DPRINTF(O3CPU, "Squashing instruction, "
11652292SN/A                "[tid:%i] [sn:%lli] PC %#x\n",
11662292SN/A                (*instIt)->threadNumber,
11672292SN/A                (*instIt)->seqNum,
11682292SN/A                (*instIt)->readPC());
11691062SN/A
11701062SN/A        // Mark it as squashed.
11712292SN/A        (*instIt)->setSquashed();
11722292SN/A
11732325SN/A        // @todo: Formulate a consistent method for deleting
11742325SN/A        // instructions from the instruction list
11752292SN/A        // Remove the instruction from the list.
11762292SN/A        removeList.push(instIt);
11772292SN/A    }
11782292SN/A}
11792292SN/A
11802292SN/Atemplate <class Impl>
11812292SN/Avoid
11822292SN/AFullO3CPU<Impl>::cleanUpRemovedInsts()
11832292SN/A{
11842292SN/A    while (!removeList.empty()) {
11852733Sktlim@umich.edu        DPRINTF(O3CPU, "Removing instruction, "
11862292SN/A                "[tid:%i] [sn:%lli] PC %#x\n",
11872292SN/A                (*removeList.front())->threadNumber,
11882292SN/A                (*removeList.front())->seqNum,
11892292SN/A                (*removeList.front())->readPC());
11902292SN/A
11912292SN/A        instList.erase(removeList.front());
11922292SN/A
11932292SN/A        removeList.pop();
11941062SN/A    }
11951062SN/A
11962292SN/A    removeInstsThisCycle = false;
11971062SN/A}
11982325SN/A/*
11991062SN/Atemplate <class Impl>
12001062SN/Avoid
12011755SN/AFullO3CPU<Impl>::removeAllInsts()
12021060SN/A{
12031060SN/A    instList.clear();
12041060SN/A}
12052325SN/A*/
12061060SN/Atemplate <class Impl>
12071060SN/Avoid
12081755SN/AFullO3CPU<Impl>::dumpInsts()
12091060SN/A{
12101060SN/A    int num = 0;
12111060SN/A
12122292SN/A    ListIt inst_list_it = instList.begin();
12132292SN/A
12142292SN/A    cprintf("Dumping Instruction List\n");
12152292SN/A
12162292SN/A    while (inst_list_it != instList.end()) {
12172292SN/A        cprintf("Instruction:%i\nPC:%#x\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
12182292SN/A                "Squashed:%i\n\n",
12192292SN/A                num, (*inst_list_it)->readPC(), (*inst_list_it)->threadNumber,
12202292SN/A                (*inst_list_it)->seqNum, (*inst_list_it)->isIssued(),
12212292SN/A                (*inst_list_it)->isSquashed());
12221060SN/A        inst_list_it++;
12231060SN/A        ++num;
12241060SN/A    }
12251060SN/A}
12262325SN/A/*
12271060SN/Atemplate <class Impl>
12281060SN/Avoid
12291755SN/AFullO3CPU<Impl>::wakeDependents(DynInstPtr &inst)
12301060SN/A{
12311060SN/A    iew.wakeDependents(inst);
12321060SN/A}
12332325SN/A*/
12342292SN/Atemplate <class Impl>
12352292SN/Avoid
12362292SN/AFullO3CPU<Impl>::wakeCPU()
12372292SN/A{
12382325SN/A    if (activityRec.active() || tickEvent.scheduled()) {
12392325SN/A        DPRINTF(Activity, "CPU already running.\n");
12402292SN/A        return;
12412292SN/A    }
12422292SN/A
12432325SN/A    DPRINTF(Activity, "Waking up CPU\n");
12442325SN/A
12452325SN/A    idleCycles += (curTick - 1) - lastRunningCycle;
12462292SN/A
12472292SN/A    tickEvent.schedule(curTick);
12482292SN/A}
12492292SN/A
12502292SN/Atemplate <class Impl>
12512292SN/Aint
12522292SN/AFullO3CPU<Impl>::getFreeTid()
12532292SN/A{
12542292SN/A    for (int i=0; i < numThreads; i++) {
12552292SN/A        if (!tids[i]) {
12562292SN/A            tids[i] = true;
12572292SN/A            return i;
12582292SN/A        }
12592292SN/A    }
12602292SN/A
12612292SN/A    return -1;
12622292SN/A}
12632292SN/A
12642292SN/Atemplate <class Impl>
12652292SN/Avoid
12662292SN/AFullO3CPU<Impl>::doContextSwitch()
12672292SN/A{
12682292SN/A    if (contextSwitch) {
12692292SN/A
12702292SN/A        //ADD CODE TO DEACTIVE THREAD HERE (???)
12712292SN/A
12722292SN/A        for (int tid=0; tid < cpuWaitList.size(); tid++) {
12732292SN/A            activateWhenReady(tid);
12742292SN/A        }
12752292SN/A
12762292SN/A        if (cpuWaitList.size() == 0)
12772292SN/A            contextSwitch = true;
12782292SN/A    }
12792292SN/A}
12802292SN/A
12812292SN/Atemplate <class Impl>
12822292SN/Avoid
12832292SN/AFullO3CPU<Impl>::updateThreadPriority()
12842292SN/A{
12852292SN/A    if (activeThreads.size() > 1)
12862292SN/A    {
12872292SN/A        //DEFAULT TO ROUND ROBIN SCHEME
12882292SN/A        //e.g. Move highest priority to end of thread list
12892292SN/A        list<unsigned>::iterator list_begin = activeThreads.begin();
12902292SN/A        list<unsigned>::iterator list_end   = activeThreads.end();
12912292SN/A
12922292SN/A        unsigned high_thread = *list_begin;
12932292SN/A
12942292SN/A        activeThreads.erase(list_begin);
12952292SN/A
12962292SN/A        activeThreads.push_back(high_thread);
12972292SN/A    }
12982292SN/A}
12991060SN/A
13001755SN/A// Forward declaration of FullO3CPU.
13012818Sksewell@umich.edutemplate class FullO3CPU<O3CPUImpl>;
1302