timing.cc revision 2867
12623SN/A/*
22623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32623SN/A * All rights reserved.
42623SN/A *
52623SN/A * Redistribution and use in source and binary forms, with or without
62623SN/A * modification, are permitted provided that the following conditions are
72623SN/A * met: redistributions of source code must retain the above copyright
82623SN/A * notice, this list of conditions and the following disclaimer;
92623SN/A * redistributions in binary form must reproduce the above copyright
102623SN/A * notice, this list of conditions and the following disclaimer in the
112623SN/A * documentation and/or other materials provided with the distribution;
122623SN/A * neither the name of the copyright holders nor the names of its
132623SN/A * contributors may be used to endorse or promote products derived from
142623SN/A * this software without specific prior written permission.
152623SN/A *
162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292623SN/A */
302623SN/A
312623SN/A#include "arch/utility.hh"
322623SN/A#include "cpu/exetrace.hh"
332623SN/A#include "cpu/simple/timing.hh"
342623SN/A#include "mem/packet_impl.hh"
352623SN/A#include "sim/builder.hh"
362623SN/A
372623SN/Ausing namespace std;
382623SN/Ausing namespace TheISA;
392623SN/A
402623SN/A
412623SN/Avoid
422623SN/ATimingSimpleCPU::init()
432623SN/A{
442623SN/A    //Create Memory Ports (conect them up)
452623SN/A    Port *mem_dport = mem->getPort("");
462623SN/A    dcachePort.setPeer(mem_dport);
472623SN/A    mem_dport->setPeer(&dcachePort);
482623SN/A
492623SN/A    Port *mem_iport = mem->getPort("");
502623SN/A    icachePort.setPeer(mem_iport);
512623SN/A    mem_iport->setPeer(&icachePort);
522623SN/A
532623SN/A    BaseCPU::init();
542623SN/A#if FULL_SYSTEM
552680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
562680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
572623SN/A
582623SN/A        // initialize CPU, including PC
592680Sktlim@umich.edu        TheISA::initCPU(tc, tc->readCpuId());
602623SN/A    }
612623SN/A#endif
622623SN/A}
632623SN/A
642623SN/ATick
652630SN/ATimingSimpleCPU::CpuPort::recvAtomic(Packet *pkt)
662623SN/A{
672623SN/A    panic("TimingSimpleCPU doesn't expect recvAtomic callback!");
682623SN/A    return curTick;
692623SN/A}
702623SN/A
712623SN/Avoid
722630SN/ATimingSimpleCPU::CpuPort::recvFunctional(Packet *pkt)
732623SN/A{
742623SN/A    panic("TimingSimpleCPU doesn't expect recvFunctional callback!");
752623SN/A}
762623SN/A
772623SN/Avoid
782623SN/ATimingSimpleCPU::CpuPort::recvStatusChange(Status status)
792623SN/A{
802631SN/A    if (status == RangeChange)
812631SN/A        return;
822631SN/A
832623SN/A    panic("TimingSimpleCPU doesn't expect recvStatusChange callback!");
842623SN/A}
852623SN/A
862623SN/ATimingSimpleCPU::TimingSimpleCPU(Params *p)
872623SN/A    : BaseSimpleCPU(p), icachePort(this), dcachePort(this)
882623SN/A{
892623SN/A    _status = Idle;
902623SN/A    ifetch_pkt = dcache_pkt = NULL;
912839Sktlim@umich.edu    drainEvent = NULL;
922867Sktlim@umich.edu    fetchEvent = NULL;
932798Sktlim@umich.edu    state = SimObject::Timing;
942623SN/A}
952623SN/A
962623SN/A
972623SN/ATimingSimpleCPU::~TimingSimpleCPU()
982623SN/A{
992623SN/A}
1002623SN/A
1012623SN/Avoid
1022623SN/ATimingSimpleCPU::serialize(ostream &os)
1032623SN/A{
1042798Sktlim@umich.edu    SERIALIZE_ENUM(_status);
1052623SN/A    BaseSimpleCPU::serialize(os);
1062623SN/A}
1072623SN/A
1082623SN/Avoid
1092623SN/ATimingSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1102623SN/A{
1112798Sktlim@umich.edu    UNSERIALIZE_ENUM(_status);
1122623SN/A    BaseSimpleCPU::unserialize(cp, section);
1132798Sktlim@umich.edu}
1142798Sktlim@umich.edu
1152798Sktlim@umich.edubool
1162839Sktlim@umich.eduTimingSimpleCPU::drain(Event *drain_event)
1172798Sktlim@umich.edu{
1182839Sktlim@umich.edu    // TimingSimpleCPU is ready to drain if it's not waiting for
1192798Sktlim@umich.edu    // an access to complete.
1202798Sktlim@umich.edu    if (status() == Idle || status() == Running || status() == SwitchedOut) {
1212839Sktlim@umich.edu        changeState(SimObject::DrainedTiming);
1222860Sktlim@umich.edu        return true;
1232798Sktlim@umich.edu    } else {
1242839Sktlim@umich.edu        changeState(SimObject::Draining);
1252839Sktlim@umich.edu        drainEvent = drain_event;
1262860Sktlim@umich.edu        return false;
1272798Sktlim@umich.edu    }
1282623SN/A}
1292623SN/A
1302623SN/Avoid
1312798Sktlim@umich.eduTimingSimpleCPU::resume()
1322623SN/A{
1332798Sktlim@umich.edu    if (_status != SwitchedOut && _status != Idle) {
1342867Sktlim@umich.edu        // Delete the old event if it existed.
1352867Sktlim@umich.edu        if (fetchEvent) {
1362867Sktlim@umich.edu            assert(!fetchEvent->scheduled());
1372867Sktlim@umich.edu            delete fetchEvent;
1382867Sktlim@umich.edu        }
1392867Sktlim@umich.edu
1402867Sktlim@umich.edu        fetchEvent =
1412867Sktlim@umich.edu            new EventWrapper<TimingSimpleCPU, &TimingSimpleCPU::fetch>(this, false);
1422867Sktlim@umich.edu        fetchEvent->schedule(curTick);
1432623SN/A    }
1442798Sktlim@umich.edu}
1452798Sktlim@umich.edu
1462798Sktlim@umich.eduvoid
1472798Sktlim@umich.eduTimingSimpleCPU::setMemoryMode(State new_mode)
1482798Sktlim@umich.edu{
1492798Sktlim@umich.edu    assert(new_mode == SimObject::Timing);
1502798Sktlim@umich.edu}
1512798Sktlim@umich.edu
1522798Sktlim@umich.eduvoid
1532798Sktlim@umich.eduTimingSimpleCPU::switchOut()
1542798Sktlim@umich.edu{
1552798Sktlim@umich.edu    assert(status() == Running || status() == Idle);
1562798Sktlim@umich.edu    _status = SwitchedOut;
1572867Sktlim@umich.edu
1582867Sktlim@umich.edu    // If we've been scheduled to resume but are then told to switch out,
1592867Sktlim@umich.edu    // we'll need to cancel it.
1602867Sktlim@umich.edu    if (fetchEvent && fetchEvent->scheduled())
1612867Sktlim@umich.edu        fetchEvent->deschedule();
1622623SN/A}
1632623SN/A
1642623SN/A
1652623SN/Avoid
1662623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
1672623SN/A{
1682623SN/A    BaseCPU::takeOverFrom(oldCPU);
1692623SN/A
1702680Sktlim@umich.edu    // if any of this CPU's ThreadContexts are active, mark the CPU as
1712623SN/A    // running and schedule its tick event.
1722680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
1732680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
1742680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
1752623SN/A            _status = Running;
1762623SN/A            break;
1772623SN/A        }
1782623SN/A    }
1792623SN/A}
1802623SN/A
1812623SN/A
1822623SN/Avoid
1832623SN/ATimingSimpleCPU::activateContext(int thread_num, int delay)
1842623SN/A{
1852623SN/A    assert(thread_num == 0);
1862683Sktlim@umich.edu    assert(thread);
1872623SN/A
1882623SN/A    assert(_status == Idle);
1892623SN/A
1902623SN/A    notIdleFraction++;
1912623SN/A    _status = Running;
1922623SN/A    // kick things off by initiating the fetch of the next instruction
1932867Sktlim@umich.edu    fetchEvent =
1942867Sktlim@umich.edu        new EventWrapper<TimingSimpleCPU, &TimingSimpleCPU::fetch>(this, false);
1952867Sktlim@umich.edu    fetchEvent->schedule(curTick + cycles(delay));
1962623SN/A}
1972623SN/A
1982623SN/A
1992623SN/Avoid
2002623SN/ATimingSimpleCPU::suspendContext(int thread_num)
2012623SN/A{
2022623SN/A    assert(thread_num == 0);
2032683Sktlim@umich.edu    assert(thread);
2042623SN/A
2052644Sstever@eecs.umich.edu    assert(_status == Running);
2062623SN/A
2072644Sstever@eecs.umich.edu    // just change status to Idle... if status != Running,
2082644Sstever@eecs.umich.edu    // completeInst() will not initiate fetch of next instruction.
2092623SN/A
2102623SN/A    notIdleFraction--;
2112623SN/A    _status = Idle;
2122623SN/A}
2132623SN/A
2142623SN/A
2152623SN/Atemplate <class T>
2162623SN/AFault
2172623SN/ATimingSimpleCPU::read(Addr addr, T &data, unsigned flags)
2182623SN/A{
2192663Sstever@eecs.umich.edu    // need to fill in CPU & thread IDs here
2202663Sstever@eecs.umich.edu    Request *data_read_req = new Request();
2212835Srdreslin@umich.edu    data_read_req->setThreadContext(0,0); //Need CPU/Thread IDS HERE
2222683Sktlim@umich.edu    data_read_req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
2232623SN/A
2242623SN/A    if (traceData) {
2252623SN/A        traceData->setAddr(data_read_req->getVaddr());
2262623SN/A    }
2272623SN/A
2282623SN/A   // translate to physical address
2292683Sktlim@umich.edu    Fault fault = thread->translateDataReadReq(data_read_req);
2302623SN/A
2312623SN/A    // Now do the access.
2322623SN/A    if (fault == NoFault) {
2332641Sstever@eecs.umich.edu        Packet *data_read_pkt =
2342641Sstever@eecs.umich.edu            new Packet(data_read_req, Packet::ReadReq, Packet::Broadcast);
2352623SN/A        data_read_pkt->dataDynamic<T>(new T);
2362623SN/A
2372630SN/A        if (!dcachePort.sendTiming(data_read_pkt)) {
2382623SN/A            _status = DcacheRetry;
2392623SN/A            dcache_pkt = data_read_pkt;
2402623SN/A        } else {
2412623SN/A            _status = DcacheWaitResponse;
2422623SN/A            dcache_pkt = NULL;
2432623SN/A        }
2442623SN/A    }
2452623SN/A
2462623SN/A    // This will need a new way to tell if it has a dcache attached.
2472623SN/A    if (data_read_req->getFlags() & UNCACHEABLE)
2482623SN/A        recordEvent("Uncached Read");
2492623SN/A
2502623SN/A    return fault;
2512623SN/A}
2522623SN/A
2532623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
2542623SN/A
2552623SN/Atemplate
2562623SN/AFault
2572623SN/ATimingSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
2582623SN/A
2592623SN/Atemplate
2602623SN/AFault
2612623SN/ATimingSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
2622623SN/A
2632623SN/Atemplate
2642623SN/AFault
2652623SN/ATimingSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
2662623SN/A
2672623SN/Atemplate
2682623SN/AFault
2692623SN/ATimingSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
2702623SN/A
2712623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
2722623SN/A
2732623SN/Atemplate<>
2742623SN/AFault
2752623SN/ATimingSimpleCPU::read(Addr addr, double &data, unsigned flags)
2762623SN/A{
2772623SN/A    return read(addr, *(uint64_t*)&data, flags);
2782623SN/A}
2792623SN/A
2802623SN/Atemplate<>
2812623SN/AFault
2822623SN/ATimingSimpleCPU::read(Addr addr, float &data, unsigned flags)
2832623SN/A{
2842623SN/A    return read(addr, *(uint32_t*)&data, flags);
2852623SN/A}
2862623SN/A
2872623SN/A
2882623SN/Atemplate<>
2892623SN/AFault
2902623SN/ATimingSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
2912623SN/A{
2922623SN/A    return read(addr, (uint32_t&)data, flags);
2932623SN/A}
2942623SN/A
2952623SN/A
2962623SN/Atemplate <class T>
2972623SN/AFault
2982623SN/ATimingSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
2992623SN/A{
3002663Sstever@eecs.umich.edu    // need to fill in CPU & thread IDs here
3012663Sstever@eecs.umich.edu    Request *data_write_req = new Request();
3022835Srdreslin@umich.edu    data_write_req->setThreadContext(0,0); //Need CPU/Thread IDS HERE
3032683Sktlim@umich.edu    data_write_req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
3042623SN/A
3052623SN/A    // translate to physical address
3062683Sktlim@umich.edu    Fault fault = thread->translateDataWriteReq(data_write_req);
3072623SN/A    // Now do the access.
3082623SN/A    if (fault == NoFault) {
3092641Sstever@eecs.umich.edu        Packet *data_write_pkt =
3102641Sstever@eecs.umich.edu            new Packet(data_write_req, Packet::WriteReq, Packet::Broadcast);
3112623SN/A        data_write_pkt->allocate();
3122623SN/A        data_write_pkt->set(data);
3132623SN/A
3142630SN/A        if (!dcachePort.sendTiming(data_write_pkt)) {
3152623SN/A            _status = DcacheRetry;
3162623SN/A            dcache_pkt = data_write_pkt;
3172623SN/A        } else {
3182623SN/A            _status = DcacheWaitResponse;
3192623SN/A            dcache_pkt = NULL;
3202623SN/A        }
3212623SN/A    }
3222623SN/A
3232623SN/A    // This will need a new way to tell if it's hooked up to a cache or not.
3242623SN/A    if (data_write_req->getFlags() & UNCACHEABLE)
3252623SN/A        recordEvent("Uncached Write");
3262623SN/A
3272623SN/A    // If the write needs to have a fault on the access, consider calling
3282623SN/A    // changeStatus() and changing it to "bad addr write" or something.
3292623SN/A    return fault;
3302623SN/A}
3312623SN/A
3322623SN/A
3332623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
3342623SN/Atemplate
3352623SN/AFault
3362623SN/ATimingSimpleCPU::write(uint64_t data, Addr addr,
3372623SN/A                       unsigned flags, uint64_t *res);
3382623SN/A
3392623SN/Atemplate
3402623SN/AFault
3412623SN/ATimingSimpleCPU::write(uint32_t data, Addr addr,
3422623SN/A                       unsigned flags, uint64_t *res);
3432623SN/A
3442623SN/Atemplate
3452623SN/AFault
3462623SN/ATimingSimpleCPU::write(uint16_t data, Addr addr,
3472623SN/A                       unsigned flags, uint64_t *res);
3482623SN/A
3492623SN/Atemplate
3502623SN/AFault
3512623SN/ATimingSimpleCPU::write(uint8_t data, Addr addr,
3522623SN/A                       unsigned flags, uint64_t *res);
3532623SN/A
3542623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
3552623SN/A
3562623SN/Atemplate<>
3572623SN/AFault
3582623SN/ATimingSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
3592623SN/A{
3602623SN/A    return write(*(uint64_t*)&data, addr, flags, res);
3612623SN/A}
3622623SN/A
3632623SN/Atemplate<>
3642623SN/AFault
3652623SN/ATimingSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
3662623SN/A{
3672623SN/A    return write(*(uint32_t*)&data, addr, flags, res);
3682623SN/A}
3692623SN/A
3702623SN/A
3712623SN/Atemplate<>
3722623SN/AFault
3732623SN/ATimingSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
3742623SN/A{
3752623SN/A    return write((uint32_t)data, addr, flags, res);
3762623SN/A}
3772623SN/A
3782623SN/A
3792623SN/Avoid
3802623SN/ATimingSimpleCPU::fetch()
3812623SN/A{
3822631SN/A    checkForInterrupts();
3832631SN/A
3842663Sstever@eecs.umich.edu    // need to fill in CPU & thread IDs here
3852663Sstever@eecs.umich.edu    Request *ifetch_req = new Request();
3862835Srdreslin@umich.edu    ifetch_req->setThreadContext(0,0); //Need CPU/Thread IDS HERE
3872662Sstever@eecs.umich.edu    Fault fault = setupFetchRequest(ifetch_req);
3882623SN/A
3892641Sstever@eecs.umich.edu    ifetch_pkt = new Packet(ifetch_req, Packet::ReadReq, Packet::Broadcast);
3902623SN/A    ifetch_pkt->dataStatic(&inst);
3912623SN/A
3922623SN/A    if (fault == NoFault) {
3932630SN/A        if (!icachePort.sendTiming(ifetch_pkt)) {
3942623SN/A            // Need to wait for retry
3952623SN/A            _status = IcacheRetry;
3962623SN/A        } else {
3972623SN/A            // Need to wait for cache to respond
3982623SN/A            _status = IcacheWaitResponse;
3992623SN/A            // ownership of packet transferred to memory system
4002623SN/A            ifetch_pkt = NULL;
4012623SN/A        }
4022623SN/A    } else {
4032644Sstever@eecs.umich.edu        // fetch fault: advance directly to next instruction (fault handler)
4042644Sstever@eecs.umich.edu        advanceInst(fault);
4052623SN/A    }
4062623SN/A}
4072623SN/A
4082623SN/A
4092623SN/Avoid
4102644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault)
4112623SN/A{
4122623SN/A    advancePC(fault);
4132623SN/A
4142631SN/A    if (_status == Running) {
4152631SN/A        // kick off fetch of next instruction... callback from icache
4162631SN/A        // response will cause that instruction to be executed,
4172631SN/A        // keeping the CPU running.
4182631SN/A        fetch();
4192631SN/A    }
4202623SN/A}
4212623SN/A
4222623SN/A
4232623SN/Avoid
4242644Sstever@eecs.umich.eduTimingSimpleCPU::completeIfetch(Packet *pkt)
4252623SN/A{
4262623SN/A    // received a response from the icache: execute the received
4272623SN/A    // instruction
4282644Sstever@eecs.umich.edu    assert(pkt->result == Packet::Success);
4292623SN/A    assert(_status == IcacheWaitResponse);
4302798Sktlim@umich.edu
4312623SN/A    _status = Running;
4322644Sstever@eecs.umich.edu
4332644Sstever@eecs.umich.edu    delete pkt->req;
4342644Sstever@eecs.umich.edu    delete pkt;
4352644Sstever@eecs.umich.edu
4362839Sktlim@umich.edu    if (getState() == SimObject::Draining) {
4372839Sktlim@umich.edu        completeDrain();
4382798Sktlim@umich.edu        return;
4392798Sktlim@umich.edu    }
4402798Sktlim@umich.edu
4412623SN/A    preExecute();
4422644Sstever@eecs.umich.edu    if (curStaticInst->isMemRef() && !curStaticInst->isDataPrefetch()) {
4432623SN/A        // load or store: just send to dcache
4442623SN/A        Fault fault = curStaticInst->initiateAcc(this, traceData);
4452644Sstever@eecs.umich.edu        if (fault == NoFault) {
4462644Sstever@eecs.umich.edu            // successfully initiated access: instruction will
4472644Sstever@eecs.umich.edu            // complete in dcache response callback
4482644Sstever@eecs.umich.edu            assert(_status == DcacheWaitResponse);
4492644Sstever@eecs.umich.edu        } else {
4502644Sstever@eecs.umich.edu            // fault: complete now to invoke fault handler
4512644Sstever@eecs.umich.edu            postExecute();
4522644Sstever@eecs.umich.edu            advanceInst(fault);
4532644Sstever@eecs.umich.edu        }
4542623SN/A    } else {
4552623SN/A        // non-memory instruction: execute completely now
4562623SN/A        Fault fault = curStaticInst->execute(this, traceData);
4572644Sstever@eecs.umich.edu        postExecute();
4582644Sstever@eecs.umich.edu        advanceInst(fault);
4592623SN/A    }
4602623SN/A}
4612623SN/A
4622623SN/A
4632623SN/Abool
4642630SN/ATimingSimpleCPU::IcachePort::recvTiming(Packet *pkt)
4652623SN/A{
4662855Srdreslin@umich.edu    if (cpu->_status == DcacheWaitResponse)
4672855Srdreslin@umich.edu        cpu->completeDataAccess(pkt);
4682855Srdreslin@umich.edu    else if (cpu->_status == IcacheWaitResponse)
4692855Srdreslin@umich.edu        cpu->completeIfetch(pkt);
4702855Srdreslin@umich.edu    else
4712855Srdreslin@umich.edu        assert("OOPS" && 0);
4722623SN/A    return true;
4732623SN/A}
4742623SN/A
4752657Ssaidi@eecs.umich.eduvoid
4762623SN/ATimingSimpleCPU::IcachePort::recvRetry()
4772623SN/A{
4782623SN/A    // we shouldn't get a retry unless we have a packet that we're
4792623SN/A    // waiting to transmit
4802623SN/A    assert(cpu->ifetch_pkt != NULL);
4812623SN/A    assert(cpu->_status == IcacheRetry);
4822623SN/A    Packet *tmp = cpu->ifetch_pkt;
4832657Ssaidi@eecs.umich.edu    if (sendTiming(tmp)) {
4842657Ssaidi@eecs.umich.edu        cpu->_status = IcacheWaitResponse;
4852657Ssaidi@eecs.umich.edu        cpu->ifetch_pkt = NULL;
4862657Ssaidi@eecs.umich.edu    }
4872623SN/A}
4882623SN/A
4892623SN/Avoid
4902623SN/ATimingSimpleCPU::completeDataAccess(Packet *pkt)
4912623SN/A{
4922623SN/A    // received a response from the dcache: complete the load or store
4932623SN/A    // instruction
4942641Sstever@eecs.umich.edu    assert(pkt->result == Packet::Success);
4952623SN/A    assert(_status == DcacheWaitResponse);
4962623SN/A    _status = Running;
4972623SN/A
4982839Sktlim@umich.edu    if (getState() == SimObject::Draining) {
4992839Sktlim@umich.edu        completeDrain();
5002798Sktlim@umich.edu
5012798Sktlim@umich.edu        delete pkt->req;
5022798Sktlim@umich.edu        delete pkt;
5032798Sktlim@umich.edu
5042798Sktlim@umich.edu        return;
5052798Sktlim@umich.edu    }
5062798Sktlim@umich.edu
5072623SN/A    Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
5082623SN/A
5092644Sstever@eecs.umich.edu    delete pkt->req;
5102644Sstever@eecs.umich.edu    delete pkt;
5112644Sstever@eecs.umich.edu
5122644Sstever@eecs.umich.edu    postExecute();
5132644Sstever@eecs.umich.edu    advanceInst(fault);
5142623SN/A}
5152623SN/A
5162623SN/A
5172798Sktlim@umich.eduvoid
5182839Sktlim@umich.eduTimingSimpleCPU::completeDrain()
5192798Sktlim@umich.edu{
5202839Sktlim@umich.edu    DPRINTF(Config, "Done draining\n");
5212839Sktlim@umich.edu    changeState(SimObject::DrainedTiming);
5222839Sktlim@umich.edu    drainEvent->process();
5232798Sktlim@umich.edu}
5242623SN/A
5252623SN/Abool
5262630SN/ATimingSimpleCPU::DcachePort::recvTiming(Packet *pkt)
5272623SN/A{
5282630SN/A    cpu->completeDataAccess(pkt);
5292623SN/A    return true;
5302623SN/A}
5312623SN/A
5322657Ssaidi@eecs.umich.eduvoid
5332623SN/ATimingSimpleCPU::DcachePort::recvRetry()
5342623SN/A{
5352623SN/A    // we shouldn't get a retry unless we have a packet that we're
5362623SN/A    // waiting to transmit
5372623SN/A    assert(cpu->dcache_pkt != NULL);
5382623SN/A    assert(cpu->_status == DcacheRetry);
5392623SN/A    Packet *tmp = cpu->dcache_pkt;
5402657Ssaidi@eecs.umich.edu    if (sendTiming(tmp)) {
5412657Ssaidi@eecs.umich.edu        cpu->_status = DcacheWaitResponse;
5422657Ssaidi@eecs.umich.edu        cpu->dcache_pkt = NULL;
5432657Ssaidi@eecs.umich.edu    }
5442623SN/A}
5452623SN/A
5462623SN/A
5472623SN/A////////////////////////////////////////////////////////////////////////
5482623SN/A//
5492623SN/A//  TimingSimpleCPU Simulation Object
5502623SN/A//
5512623SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(TimingSimpleCPU)
5522623SN/A
5532623SN/A    Param<Counter> max_insts_any_thread;
5542623SN/A    Param<Counter> max_insts_all_threads;
5552623SN/A    Param<Counter> max_loads_any_thread;
5562623SN/A    Param<Counter> max_loads_all_threads;
5572623SN/A    SimObjectParam<MemObject *> mem;
5582623SN/A
5592623SN/A#if FULL_SYSTEM
5602623SN/A    SimObjectParam<AlphaITB *> itb;
5612623SN/A    SimObjectParam<AlphaDTB *> dtb;
5622623SN/A    SimObjectParam<System *> system;
5632623SN/A    Param<int> cpu_id;
5642623SN/A    Param<Tick> profile;
5652623SN/A#else
5662623SN/A    SimObjectParam<Process *> workload;
5672623SN/A#endif // FULL_SYSTEM
5682623SN/A
5692623SN/A    Param<int> clock;
5702623SN/A
5712623SN/A    Param<bool> defer_registration;
5722623SN/A    Param<int> width;
5732623SN/A    Param<bool> function_trace;
5742623SN/A    Param<Tick> function_trace_start;
5752623SN/A    Param<bool> simulate_stalls;
5762623SN/A
5772623SN/AEND_DECLARE_SIM_OBJECT_PARAMS(TimingSimpleCPU)
5782623SN/A
5792623SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(TimingSimpleCPU)
5802623SN/A
5812623SN/A    INIT_PARAM(max_insts_any_thread,
5822623SN/A               "terminate when any thread reaches this inst count"),
5832623SN/A    INIT_PARAM(max_insts_all_threads,
5842623SN/A               "terminate when all threads have reached this inst count"),
5852623SN/A    INIT_PARAM(max_loads_any_thread,
5862623SN/A               "terminate when any thread reaches this load count"),
5872623SN/A    INIT_PARAM(max_loads_all_threads,
5882623SN/A               "terminate when all threads have reached this load count"),
5892623SN/A    INIT_PARAM(mem, "memory"),
5902623SN/A
5912623SN/A#if FULL_SYSTEM
5922623SN/A    INIT_PARAM(itb, "Instruction TLB"),
5932623SN/A    INIT_PARAM(dtb, "Data TLB"),
5942623SN/A    INIT_PARAM(system, "system object"),
5952623SN/A    INIT_PARAM(cpu_id, "processor ID"),
5962623SN/A    INIT_PARAM(profile, ""),
5972623SN/A#else
5982623SN/A    INIT_PARAM(workload, "processes to run"),
5992623SN/A#endif // FULL_SYSTEM
6002623SN/A
6012623SN/A    INIT_PARAM(clock, "clock speed"),
6022623SN/A    INIT_PARAM(defer_registration, "defer system registration (for sampling)"),
6032623SN/A    INIT_PARAM(width, "cpu width"),
6042623SN/A    INIT_PARAM(function_trace, "Enable function trace"),
6052623SN/A    INIT_PARAM(function_trace_start, "Cycle to start function trace"),
6062623SN/A    INIT_PARAM(simulate_stalls, "Simulate cache stall cycles")
6072623SN/A
6082623SN/AEND_INIT_SIM_OBJECT_PARAMS(TimingSimpleCPU)
6092623SN/A
6102623SN/A
6112623SN/ACREATE_SIM_OBJECT(TimingSimpleCPU)
6122623SN/A{
6132623SN/A    TimingSimpleCPU::Params *params = new TimingSimpleCPU::Params();
6142623SN/A    params->name = getInstanceName();
6152623SN/A    params->numberOfThreads = 1;
6162623SN/A    params->max_insts_any_thread = max_insts_any_thread;
6172623SN/A    params->max_insts_all_threads = max_insts_all_threads;
6182623SN/A    params->max_loads_any_thread = max_loads_any_thread;
6192623SN/A    params->max_loads_all_threads = max_loads_all_threads;
6202623SN/A    params->deferRegistration = defer_registration;
6212623SN/A    params->clock = clock;
6222623SN/A    params->functionTrace = function_trace;
6232623SN/A    params->functionTraceStart = function_trace_start;
6242623SN/A    params->mem = mem;
6252623SN/A
6262623SN/A#if FULL_SYSTEM
6272623SN/A    params->itb = itb;
6282623SN/A    params->dtb = dtb;
6292623SN/A    params->system = system;
6302623SN/A    params->cpu_id = cpu_id;
6312623SN/A    params->profile = profile;
6322623SN/A#else
6332623SN/A    params->process = workload;
6342623SN/A#endif
6352623SN/A
6362623SN/A    TimingSimpleCPU *cpu = new TimingSimpleCPU(params);
6372623SN/A    return cpu;
6382623SN/A}
6392623SN/A
6402623SN/AREGISTER_SIM_OBJECT("TimingSimpleCPU", TimingSimpleCPU)
6412623SN/A
642