timing.cc revision 6102
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
313170Sstever@eecs.umich.edu#include "arch/locked_mem.hh"
325103Ssaidi@eecs.umich.edu#include "arch/mmaped_ipr.hh"
332623SN/A#include "arch/utility.hh"
344040Ssaidi@eecs.umich.edu#include "base/bigint.hh"
352623SN/A#include "cpu/exetrace.hh"
362623SN/A#include "cpu/simple/timing.hh"
373348Sbinkertn@umich.edu#include "mem/packet.hh"
383348Sbinkertn@umich.edu#include "mem/packet_access.hh"
394762Snate@binkert.org#include "params/TimingSimpleCPU.hh"
402901Ssaidi@eecs.umich.edu#include "sim/system.hh"
412623SN/A
422623SN/Ausing namespace std;
432623SN/Ausing namespace TheISA;
442623SN/A
452856Srdreslin@umich.eduPort *
462856Srdreslin@umich.eduTimingSimpleCPU::getPort(const std::string &if_name, int idx)
472856Srdreslin@umich.edu{
482856Srdreslin@umich.edu    if (if_name == "dcache_port")
492856Srdreslin@umich.edu        return &dcachePort;
502856Srdreslin@umich.edu    else if (if_name == "icache_port")
512856Srdreslin@umich.edu        return &icachePort;
522856Srdreslin@umich.edu    else
532856Srdreslin@umich.edu        panic("No Such Port\n");
542856Srdreslin@umich.edu}
552623SN/A
562623SN/Avoid
572623SN/ATimingSimpleCPU::init()
582623SN/A{
592623SN/A    BaseCPU::init();
602623SN/A#if FULL_SYSTEM
612680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
622680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
632623SN/A
642623SN/A        // initialize CPU, including PC
655712Shsul@eecs.umich.edu        TheISA::initCPU(tc, _cpuId);
662623SN/A    }
672623SN/A#endif
682623SN/A}
692623SN/A
702623SN/ATick
713349Sbinkertn@umich.eduTimingSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt)
722623SN/A{
732623SN/A    panic("TimingSimpleCPU doesn't expect recvAtomic callback!");
742623SN/A    return curTick;
752623SN/A}
762623SN/A
772623SN/Avoid
783349Sbinkertn@umich.eduTimingSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt)
792623SN/A{
803184Srdreslin@umich.edu    //No internal storage to update, jusst return
813184Srdreslin@umich.edu    return;
822623SN/A}
832623SN/A
842623SN/Avoid
852623SN/ATimingSimpleCPU::CpuPort::recvStatusChange(Status status)
862623SN/A{
873647Srdreslin@umich.edu    if (status == RangeChange) {
883647Srdreslin@umich.edu        if (!snoopRangeSent) {
893647Srdreslin@umich.edu            snoopRangeSent = true;
903647Srdreslin@umich.edu            sendStatusChange(Port::RangeChange);
913647Srdreslin@umich.edu        }
922631SN/A        return;
933647Srdreslin@umich.edu    }
942631SN/A
952623SN/A    panic("TimingSimpleCPU doesn't expect recvStatusChange callback!");
962623SN/A}
972623SN/A
982948Ssaidi@eecs.umich.edu
992948Ssaidi@eecs.umich.eduvoid
1003349Sbinkertn@umich.eduTimingSimpleCPU::CpuPort::TickEvent::schedule(PacketPtr _pkt, Tick t)
1012948Ssaidi@eecs.umich.edu{
1022948Ssaidi@eecs.umich.edu    pkt = _pkt;
1035606Snate@binkert.org    cpu->schedule(this, t);
1042948Ssaidi@eecs.umich.edu}
1052948Ssaidi@eecs.umich.edu
1065529Snate@binkert.orgTimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p)
1075894Sgblack@eecs.umich.edu    : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this, p->clock),
1085894Sgblack@eecs.umich.edu    dcachePort(this, p->clock), fetchEvent(this)
1092623SN/A{
1102623SN/A    _status = Idle;
1113647Srdreslin@umich.edu
1123647Srdreslin@umich.edu    icachePort.snoopRangeSent = false;
1133647Srdreslin@umich.edu    dcachePort.snoopRangeSent = false;
1143647Srdreslin@umich.edu
1152623SN/A    ifetch_pkt = dcache_pkt = NULL;
1162839Sktlim@umich.edu    drainEvent = NULL;
1173222Sktlim@umich.edu    previousTick = 0;
1182901Ssaidi@eecs.umich.edu    changeState(SimObject::Running);
1192623SN/A}
1202623SN/A
1212623SN/A
1222623SN/ATimingSimpleCPU::~TimingSimpleCPU()
1232623SN/A{
1242623SN/A}
1252623SN/A
1262623SN/Avoid
1272623SN/ATimingSimpleCPU::serialize(ostream &os)
1282623SN/A{
1292915Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
1302915Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
1312623SN/A    BaseSimpleCPU::serialize(os);
1322623SN/A}
1332623SN/A
1342623SN/Avoid
1352623SN/ATimingSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1362623SN/A{
1372915Sktlim@umich.edu    SimObject::State so_state;
1382915Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
1392623SN/A    BaseSimpleCPU::unserialize(cp, section);
1402798Sktlim@umich.edu}
1412798Sktlim@umich.edu
1422901Ssaidi@eecs.umich.eduunsigned int
1432839Sktlim@umich.eduTimingSimpleCPU::drain(Event *drain_event)
1442798Sktlim@umich.edu{
1452839Sktlim@umich.edu    // TimingSimpleCPU is ready to drain if it's not waiting for
1462798Sktlim@umich.edu    // an access to complete.
1475496Ssaidi@eecs.umich.edu    if (_status == Idle || _status == Running || _status == SwitchedOut) {
1482901Ssaidi@eecs.umich.edu        changeState(SimObject::Drained);
1492901Ssaidi@eecs.umich.edu        return 0;
1502798Sktlim@umich.edu    } else {
1512839Sktlim@umich.edu        changeState(SimObject::Draining);
1522839Sktlim@umich.edu        drainEvent = drain_event;
1532901Ssaidi@eecs.umich.edu        return 1;
1542798Sktlim@umich.edu    }
1552623SN/A}
1562623SN/A
1572623SN/Avoid
1582798Sktlim@umich.eduTimingSimpleCPU::resume()
1592623SN/A{
1605221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Resume\n");
1612798Sktlim@umich.edu    if (_status != SwitchedOut && _status != Idle) {
1624762Snate@binkert.org        assert(system->getMemoryMode() == Enums::timing);
1633201Shsul@eecs.umich.edu
1645710Scws3k@cs.virginia.edu        if (fetchEvent.scheduled())
1655710Scws3k@cs.virginia.edu           deschedule(fetchEvent);
1662915Sktlim@umich.edu
1675710Scws3k@cs.virginia.edu        schedule(fetchEvent, nextCycle());
1682623SN/A    }
1692798Sktlim@umich.edu
1702901Ssaidi@eecs.umich.edu    changeState(SimObject::Running);
1712798Sktlim@umich.edu}
1722798Sktlim@umich.edu
1732798Sktlim@umich.eduvoid
1742798Sktlim@umich.eduTimingSimpleCPU::switchOut()
1752798Sktlim@umich.edu{
1765496Ssaidi@eecs.umich.edu    assert(_status == Running || _status == Idle);
1772798Sktlim@umich.edu    _status = SwitchedOut;
1785099Ssaidi@eecs.umich.edu    numCycles += tickToCycles(curTick - previousTick);
1792867Sktlim@umich.edu
1802867Sktlim@umich.edu    // If we've been scheduled to resume but are then told to switch out,
1812867Sktlim@umich.edu    // we'll need to cancel it.
1825710Scws3k@cs.virginia.edu    if (fetchEvent.scheduled())
1835606Snate@binkert.org        deschedule(fetchEvent);
1842623SN/A}
1852623SN/A
1862623SN/A
1872623SN/Avoid
1882623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
1892623SN/A{
1904192Sktlim@umich.edu    BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort);
1912623SN/A
1922680Sktlim@umich.edu    // if any of this CPU's ThreadContexts are active, mark the CPU as
1932623SN/A    // running and schedule its tick event.
1942680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
1952680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
1962680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
1972623SN/A            _status = Running;
1982623SN/A            break;
1992623SN/A        }
2002623SN/A    }
2013201Shsul@eecs.umich.edu
2023201Shsul@eecs.umich.edu    if (_status != Running) {
2033201Shsul@eecs.umich.edu        _status = Idle;
2043201Shsul@eecs.umich.edu    }
2055169Ssaidi@eecs.umich.edu    assert(threadContexts.size() == 1);
2065101Ssaidi@eecs.umich.edu    previousTick = curTick;
2072623SN/A}
2082623SN/A
2092623SN/A
2102623SN/Avoid
2112623SN/ATimingSimpleCPU::activateContext(int thread_num, int delay)
2122623SN/A{
2135221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay);
2145221Ssaidi@eecs.umich.edu
2152623SN/A    assert(thread_num == 0);
2162683Sktlim@umich.edu    assert(thread);
2172623SN/A
2182623SN/A    assert(_status == Idle);
2192623SN/A
2202623SN/A    notIdleFraction++;
2212623SN/A    _status = Running;
2223686Sktlim@umich.edu
2232623SN/A    // kick things off by initiating the fetch of the next instruction
2245606Snate@binkert.org    schedule(fetchEvent, nextCycle(curTick + ticks(delay)));
2252623SN/A}
2262623SN/A
2272623SN/A
2282623SN/Avoid
2292623SN/ATimingSimpleCPU::suspendContext(int thread_num)
2302623SN/A{
2315221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
2325221Ssaidi@eecs.umich.edu
2332623SN/A    assert(thread_num == 0);
2342683Sktlim@umich.edu    assert(thread);
2352623SN/A
2366043Sgblack@eecs.umich.edu    if (_status == Idle)
2376043Sgblack@eecs.umich.edu        return;
2386043Sgblack@eecs.umich.edu
2392644Sstever@eecs.umich.edu    assert(_status == Running);
2402623SN/A
2412644Sstever@eecs.umich.edu    // just change status to Idle... if status != Running,
2422644Sstever@eecs.umich.edu    // completeInst() will not initiate fetch of next instruction.
2432623SN/A
2442623SN/A    notIdleFraction--;
2452623SN/A    _status = Idle;
2462623SN/A}
2472623SN/A
2485728Sgblack@eecs.umich.edubool
2495728Sgblack@eecs.umich.eduTimingSimpleCPU::handleReadPacket(PacketPtr pkt)
2505728Sgblack@eecs.umich.edu{
2515728Sgblack@eecs.umich.edu    RequestPtr req = pkt->req;
2525728Sgblack@eecs.umich.edu    if (req->isMmapedIpr()) {
2535728Sgblack@eecs.umich.edu        Tick delay;
2545728Sgblack@eecs.umich.edu        delay = TheISA::handleIprRead(thread->getTC(), pkt);
2555728Sgblack@eecs.umich.edu        new IprEvent(pkt, this, nextCycle(curTick + delay));
2565728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2575728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2585728Sgblack@eecs.umich.edu    } else if (!dcachePort.sendTiming(pkt)) {
2595728Sgblack@eecs.umich.edu        _status = DcacheRetry;
2605728Sgblack@eecs.umich.edu        dcache_pkt = pkt;
2615728Sgblack@eecs.umich.edu    } else {
2625728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2635728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
2645728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2655728Sgblack@eecs.umich.edu    }
2665728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
2675728Sgblack@eecs.umich.edu}
2682623SN/A
2695894Sgblack@eecs.umich.eduvoid
2705894Sgblack@eecs.umich.eduTimingSimpleCPU::sendData(Fault fault, RequestPtr req,
2715894Sgblack@eecs.umich.edu        uint8_t *data, uint64_t *res, bool read)
2725744Sgblack@eecs.umich.edu{
2735894Sgblack@eecs.umich.edu    _status = Running;
2745894Sgblack@eecs.umich.edu    if (fault != NoFault) {
2755894Sgblack@eecs.umich.edu        delete data;
2765894Sgblack@eecs.umich.edu        delete req;
2775744Sgblack@eecs.umich.edu
2785894Sgblack@eecs.umich.edu        translationFault(fault);
2795894Sgblack@eecs.umich.edu        return;
2805894Sgblack@eecs.umich.edu    }
2815894Sgblack@eecs.umich.edu    PacketPtr pkt;
2825894Sgblack@eecs.umich.edu    buildPacket(pkt, req, read);
2835894Sgblack@eecs.umich.edu    pkt->dataDynamic<uint8_t>(data);
2845894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2855894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2865894Sgblack@eecs.umich.edu        pkt->makeResponse();
2875894Sgblack@eecs.umich.edu        completeDataAccess(pkt);
2885894Sgblack@eecs.umich.edu    } else if (read) {
2895894Sgblack@eecs.umich.edu        handleReadPacket(pkt);
2905894Sgblack@eecs.umich.edu    } else {
2915894Sgblack@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
2925894Sgblack@eecs.umich.edu
2936102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
2945894Sgblack@eecs.umich.edu            do_access = TheISA::handleLockedWrite(thread, req);
2955894Sgblack@eecs.umich.edu        } else if (req->isCondSwap()) {
2965894Sgblack@eecs.umich.edu            assert(res);
2975894Sgblack@eecs.umich.edu            req->setExtraData(*res);
2985894Sgblack@eecs.umich.edu        }
2995894Sgblack@eecs.umich.edu
3005894Sgblack@eecs.umich.edu        if (do_access) {
3015894Sgblack@eecs.umich.edu            dcache_pkt = pkt;
3025894Sgblack@eecs.umich.edu            handleWritePacket();
3035894Sgblack@eecs.umich.edu        } else {
3045894Sgblack@eecs.umich.edu            _status = DcacheWaitResponse;
3055894Sgblack@eecs.umich.edu            completeDataAccess(pkt);
3065894Sgblack@eecs.umich.edu        }
3075894Sgblack@eecs.umich.edu    }
3085894Sgblack@eecs.umich.edu}
3095894Sgblack@eecs.umich.edu
3105894Sgblack@eecs.umich.eduvoid
3115894Sgblack@eecs.umich.eduTimingSimpleCPU::sendSplitData(Fault fault1, Fault fault2,
3125894Sgblack@eecs.umich.edu        RequestPtr req1, RequestPtr req2, RequestPtr req,
3135894Sgblack@eecs.umich.edu        uint8_t *data, bool read)
3145894Sgblack@eecs.umich.edu{
3155894Sgblack@eecs.umich.edu    _status = Running;
3165894Sgblack@eecs.umich.edu    if (fault1 != NoFault || fault2 != NoFault) {
3175894Sgblack@eecs.umich.edu        delete data;
3185890Sgblack@eecs.umich.edu        delete req1;
3195894Sgblack@eecs.umich.edu        delete req2;
3205894Sgblack@eecs.umich.edu        if (fault1 != NoFault)
3215894Sgblack@eecs.umich.edu            translationFault(fault1);
3225894Sgblack@eecs.umich.edu        else if (fault2 != NoFault)
3235894Sgblack@eecs.umich.edu            translationFault(fault2);
3245894Sgblack@eecs.umich.edu        return;
3255894Sgblack@eecs.umich.edu    }
3265894Sgblack@eecs.umich.edu    PacketPtr pkt1, pkt2;
3275894Sgblack@eecs.umich.edu    buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
3285894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3295894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
3305894Sgblack@eecs.umich.edu        pkt1->makeResponse();
3315894Sgblack@eecs.umich.edu        completeDataAccess(pkt1);
3325894Sgblack@eecs.umich.edu    } else if (read) {
3335894Sgblack@eecs.umich.edu        if (handleReadPacket(pkt1)) {
3345894Sgblack@eecs.umich.edu            SplitFragmentSenderState * send_state =
3355894Sgblack@eecs.umich.edu                dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3365894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3375894Sgblack@eecs.umich.edu            if (handleReadPacket(pkt2)) {
3385894Sgblack@eecs.umich.edu                send_state = dynamic_cast<SplitFragmentSenderState *>(
3395894Sgblack@eecs.umich.edu                        pkt1->senderState);
3405894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3415894Sgblack@eecs.umich.edu            }
3425894Sgblack@eecs.umich.edu        }
3435894Sgblack@eecs.umich.edu    } else {
3445894Sgblack@eecs.umich.edu        dcache_pkt = pkt1;
3455894Sgblack@eecs.umich.edu        if (handleWritePacket()) {
3465894Sgblack@eecs.umich.edu            SplitFragmentSenderState * send_state =
3475894Sgblack@eecs.umich.edu                dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3485894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3495894Sgblack@eecs.umich.edu            dcache_pkt = pkt2;
3505894Sgblack@eecs.umich.edu            if (handleWritePacket()) {
3515894Sgblack@eecs.umich.edu                send_state = dynamic_cast<SplitFragmentSenderState *>(
3525894Sgblack@eecs.umich.edu                        pkt1->senderState);
3535894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3545894Sgblack@eecs.umich.edu            }
3555894Sgblack@eecs.umich.edu        }
3565894Sgblack@eecs.umich.edu    }
3575894Sgblack@eecs.umich.edu}
3585894Sgblack@eecs.umich.edu
3595894Sgblack@eecs.umich.eduvoid
3605894Sgblack@eecs.umich.eduTimingSimpleCPU::translationFault(Fault fault)
3615894Sgblack@eecs.umich.edu{
3625894Sgblack@eecs.umich.edu    numCycles += tickToCycles(curTick - previousTick);
3635894Sgblack@eecs.umich.edu    previousTick = curTick;
3645894Sgblack@eecs.umich.edu
3655894Sgblack@eecs.umich.edu    if (traceData) {
3665894Sgblack@eecs.umich.edu        // Since there was a fault, we shouldn't trace this instruction.
3675894Sgblack@eecs.umich.edu        delete traceData;
3685894Sgblack@eecs.umich.edu        traceData = NULL;
3695744Sgblack@eecs.umich.edu    }
3705744Sgblack@eecs.umich.edu
3715894Sgblack@eecs.umich.edu    postExecute();
3725894Sgblack@eecs.umich.edu
3735894Sgblack@eecs.umich.edu    if (getState() == SimObject::Draining) {
3745894Sgblack@eecs.umich.edu        advancePC(fault);
3755894Sgblack@eecs.umich.edu        completeDrain();
3765894Sgblack@eecs.umich.edu    } else {
3775894Sgblack@eecs.umich.edu        advanceInst(fault);
3785894Sgblack@eecs.umich.edu    }
3795894Sgblack@eecs.umich.edu}
3805894Sgblack@eecs.umich.edu
3815894Sgblack@eecs.umich.eduvoid
3825894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
3835894Sgblack@eecs.umich.edu{
3845894Sgblack@eecs.umich.edu    MemCmd cmd;
3855894Sgblack@eecs.umich.edu    if (read) {
3865894Sgblack@eecs.umich.edu        cmd = MemCmd::ReadReq;
3876102Sgblack@eecs.umich.edu        if (req->isLLSC())
3885894Sgblack@eecs.umich.edu            cmd = MemCmd::LoadLockedReq;
3895894Sgblack@eecs.umich.edu    } else {
3905894Sgblack@eecs.umich.edu        cmd = MemCmd::WriteReq;
3916102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
3925894Sgblack@eecs.umich.edu            cmd = MemCmd::StoreCondReq;
3935894Sgblack@eecs.umich.edu        } else if (req->isSwap()) {
3945894Sgblack@eecs.umich.edu            cmd = MemCmd::SwapReq;
3955894Sgblack@eecs.umich.edu        }
3965894Sgblack@eecs.umich.edu    }
3975894Sgblack@eecs.umich.edu    pkt = new Packet(req, cmd, Packet::Broadcast);
3985894Sgblack@eecs.umich.edu}
3995894Sgblack@eecs.umich.edu
4005894Sgblack@eecs.umich.eduvoid
4015894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
4025894Sgblack@eecs.umich.edu        RequestPtr req1, RequestPtr req2, RequestPtr req,
4035894Sgblack@eecs.umich.edu        uint8_t *data, bool read)
4045894Sgblack@eecs.umich.edu{
4055894Sgblack@eecs.umich.edu    pkt1 = pkt2 = NULL;
4065894Sgblack@eecs.umich.edu
4075744Sgblack@eecs.umich.edu    assert(!req1->isMmapedIpr() && !req2->isMmapedIpr());
4085744Sgblack@eecs.umich.edu
4095894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
4105894Sgblack@eecs.umich.edu        buildPacket(pkt1, req, read);
4115894Sgblack@eecs.umich.edu        return;
4125894Sgblack@eecs.umich.edu    }
4135894Sgblack@eecs.umich.edu
4145894Sgblack@eecs.umich.edu    buildPacket(pkt1, req1, read);
4155894Sgblack@eecs.umich.edu    buildPacket(pkt2, req2, read);
4165894Sgblack@eecs.umich.edu
4175744Sgblack@eecs.umich.edu    req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags());
4185744Sgblack@eecs.umich.edu    PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand(),
4195744Sgblack@eecs.umich.edu                               Packet::Broadcast);
4205744Sgblack@eecs.umich.edu
4215744Sgblack@eecs.umich.edu    pkt->dataDynamic<uint8_t>(data);
4225744Sgblack@eecs.umich.edu    pkt1->dataStatic<uint8_t>(data);
4235744Sgblack@eecs.umich.edu    pkt2->dataStatic<uint8_t>(data + req1->getSize());
4245744Sgblack@eecs.umich.edu
4255744Sgblack@eecs.umich.edu    SplitMainSenderState * main_send_state = new SplitMainSenderState;
4265744Sgblack@eecs.umich.edu    pkt->senderState = main_send_state;
4275744Sgblack@eecs.umich.edu    main_send_state->fragments[0] = pkt1;
4285744Sgblack@eecs.umich.edu    main_send_state->fragments[1] = pkt2;
4295744Sgblack@eecs.umich.edu    main_send_state->outstanding = 2;
4305744Sgblack@eecs.umich.edu    pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
4315744Sgblack@eecs.umich.edu    pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
4325744Sgblack@eecs.umich.edu}
4335744Sgblack@eecs.umich.edu
4342623SN/Atemplate <class T>
4352623SN/AFault
4362623SN/ATimingSimpleCPU::read(Addr addr, T &data, unsigned flags)
4372623SN/A{
4385728Sgblack@eecs.umich.edu    Fault fault;
4395728Sgblack@eecs.umich.edu    const int asid = 0;
4405728Sgblack@eecs.umich.edu    const int thread_id = 0;
4415728Sgblack@eecs.umich.edu    const Addr pc = thread->readPC();
4425728Sgblack@eecs.umich.edu    int block_size = dcachePort.peerBlockSize();
4435728Sgblack@eecs.umich.edu    int data_size = sizeof(T);
4442623SN/A
4455744Sgblack@eecs.umich.edu    RequestPtr req  = new Request(asid, addr, data_size,
4465744Sgblack@eecs.umich.edu                                  flags, pc, _cpuId, thread_id);
4475728Sgblack@eecs.umich.edu
4485744Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + data_size - 1, block_size);
4495744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4505728Sgblack@eecs.umich.edu
4515894Sgblack@eecs.umich.edu
4525894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4535744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4545894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4556102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4565894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4575894Sgblack@eecs.umich.edu
4585894Sgblack@eecs.umich.edu        typedef SplitDataTranslation::WholeTranslationState WholeState;
4595894Sgblack@eecs.umich.edu        WholeState *state = new WholeState(req1, req2, req,
4606023Snate@binkert.org                                           (uint8_t *)(new T), BaseTLB::Read);
4615894Sgblack@eecs.umich.edu        thread->dtb->translateTiming(req1, tc,
4626023Snate@binkert.org                new SplitDataTranslation(this, 0, state), BaseTLB::Read);
4635894Sgblack@eecs.umich.edu        thread->dtb->translateTiming(req2, tc,
4646023Snate@binkert.org                new SplitDataTranslation(this, 1, state), BaseTLB::Read);
4655744Sgblack@eecs.umich.edu    } else {
4666023Snate@binkert.org        DataTranslation *translation =
4676023Snate@binkert.org            new DataTranslation(this, (uint8_t *)(new T), NULL, BaseTLB::Read);
4686023Snate@binkert.org        thread->dtb->translateTiming(req, tc, translation, BaseTLB::Read);
4692623SN/A    }
4702623SN/A
4715408Sgblack@eecs.umich.edu    if (traceData) {
4725408Sgblack@eecs.umich.edu        traceData->setData(data);
4735728Sgblack@eecs.umich.edu        traceData->setAddr(addr);
4745408Sgblack@eecs.umich.edu    }
4755728Sgblack@eecs.umich.edu
4765728Sgblack@eecs.umich.edu    // This will need a new way to tell if it has a dcache attached.
4775728Sgblack@eecs.umich.edu    if (req->isUncacheable())
4785728Sgblack@eecs.umich.edu        recordEvent("Uncached Read");
4795728Sgblack@eecs.umich.edu
4805728Sgblack@eecs.umich.edu    return NoFault;
4812623SN/A}
4822623SN/A
4832623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
4842623SN/A
4852623SN/Atemplate
4862623SN/AFault
4874040Ssaidi@eecs.umich.eduTimingSimpleCPU::read(Addr addr, Twin64_t &data, unsigned flags);
4884040Ssaidi@eecs.umich.edu
4894040Ssaidi@eecs.umich.edutemplate
4904040Ssaidi@eecs.umich.eduFault
4914115Ssaidi@eecs.umich.eduTimingSimpleCPU::read(Addr addr, Twin32_t &data, unsigned flags);
4924115Ssaidi@eecs.umich.edu
4934115Ssaidi@eecs.umich.edutemplate
4944115Ssaidi@eecs.umich.eduFault
4952623SN/ATimingSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
4962623SN/A
4972623SN/Atemplate
4982623SN/AFault
4992623SN/ATimingSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
5002623SN/A
5012623SN/Atemplate
5022623SN/AFault
5032623SN/ATimingSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
5042623SN/A
5052623SN/Atemplate
5062623SN/AFault
5072623SN/ATimingSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
5082623SN/A
5092623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
5102623SN/A
5112623SN/Atemplate<>
5122623SN/AFault
5132623SN/ATimingSimpleCPU::read(Addr addr, double &data, unsigned flags)
5142623SN/A{
5152623SN/A    return read(addr, *(uint64_t*)&data, flags);
5162623SN/A}
5172623SN/A
5182623SN/Atemplate<>
5192623SN/AFault
5202623SN/ATimingSimpleCPU::read(Addr addr, float &data, unsigned flags)
5212623SN/A{
5222623SN/A    return read(addr, *(uint32_t*)&data, flags);
5232623SN/A}
5242623SN/A
5252623SN/A
5262623SN/Atemplate<>
5272623SN/AFault
5282623SN/ATimingSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
5292623SN/A{
5302623SN/A    return read(addr, (uint32_t&)data, flags);
5312623SN/A}
5322623SN/A
5335728Sgblack@eecs.umich.edubool
5345728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket()
5355728Sgblack@eecs.umich.edu{
5365728Sgblack@eecs.umich.edu    RequestPtr req = dcache_pkt->req;
5375728Sgblack@eecs.umich.edu    if (req->isMmapedIpr()) {
5385728Sgblack@eecs.umich.edu        Tick delay;
5395728Sgblack@eecs.umich.edu        delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
5405728Sgblack@eecs.umich.edu        new IprEvent(dcache_pkt, this, nextCycle(curTick + delay));
5415728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
5425728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
5435728Sgblack@eecs.umich.edu    } else if (!dcachePort.sendTiming(dcache_pkt)) {
5445728Sgblack@eecs.umich.edu        _status = DcacheRetry;
5455728Sgblack@eecs.umich.edu    } else {
5465728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
5475728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
5485728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
5495728Sgblack@eecs.umich.edu    }
5505728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
5515728Sgblack@eecs.umich.edu}
5522623SN/A
5532623SN/Atemplate <class T>
5542623SN/AFault
5552623SN/ATimingSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
5562623SN/A{
5575728Sgblack@eecs.umich.edu    const int asid = 0;
5585728Sgblack@eecs.umich.edu    const int thread_id = 0;
5595728Sgblack@eecs.umich.edu    const Addr pc = thread->readPC();
5605728Sgblack@eecs.umich.edu    int block_size = dcachePort.peerBlockSize();
5615728Sgblack@eecs.umich.edu    int data_size = sizeof(T);
5623169Sstever@eecs.umich.edu
5635744Sgblack@eecs.umich.edu    RequestPtr req = new Request(asid, addr, data_size,
5645744Sgblack@eecs.umich.edu                                 flags, pc, _cpuId, thread_id);
5655728Sgblack@eecs.umich.edu
5665744Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + data_size - 1, block_size);
5675744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
5685728Sgblack@eecs.umich.edu
5695894Sgblack@eecs.umich.edu    T *dataP = new T;
5706012Ssteve.reinhardt@amd.com    *dataP = TheISA::htog(data);
5715894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
5725744Sgblack@eecs.umich.edu    if (split_addr > addr) {
5735894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
5746102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
5755894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
5765894Sgblack@eecs.umich.edu
5775894Sgblack@eecs.umich.edu        typedef SplitDataTranslation::WholeTranslationState WholeState;
5785894Sgblack@eecs.umich.edu        WholeState *state = new WholeState(req1, req2, req,
5796023Snate@binkert.org                (uint8_t *)dataP, BaseTLB::Write);
5805894Sgblack@eecs.umich.edu        thread->dtb->translateTiming(req1, tc,
5816023Snate@binkert.org                new SplitDataTranslation(this, 0, state), BaseTLB::Write);
5825894Sgblack@eecs.umich.edu        thread->dtb->translateTiming(req2, tc,
5836023Snate@binkert.org                new SplitDataTranslation(this, 1, state), BaseTLB::Write);
5845744Sgblack@eecs.umich.edu    } else {
5856023Snate@binkert.org        DataTranslation *translation =
5866023Snate@binkert.org            new DataTranslation(this, (uint8_t *)dataP, res, BaseTLB::Write);
5876023Snate@binkert.org        thread->dtb->translateTiming(req, tc, translation, BaseTLB::Write);
5882623SN/A    }
5892623SN/A
5905408Sgblack@eecs.umich.edu    if (traceData) {
5915728Sgblack@eecs.umich.edu        traceData->setAddr(req->getVaddr());
5925408Sgblack@eecs.umich.edu        traceData->setData(data);
5935408Sgblack@eecs.umich.edu    }
5942623SN/A
5955728Sgblack@eecs.umich.edu    // This will need a new way to tell if it's hooked up to a cache or not.
5965728Sgblack@eecs.umich.edu    if (req->isUncacheable())
5975728Sgblack@eecs.umich.edu        recordEvent("Uncached Write");
5985728Sgblack@eecs.umich.edu
5992623SN/A    // If the write needs to have a fault on the access, consider calling
6002623SN/A    // changeStatus() and changing it to "bad addr write" or something.
6015728Sgblack@eecs.umich.edu    return NoFault;
6022623SN/A}
6032623SN/A
6042623SN/A
6052623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
6062623SN/Atemplate
6072623SN/AFault
6084224Sgblack@eecs.umich.eduTimingSimpleCPU::write(Twin32_t data, Addr addr,
6094224Sgblack@eecs.umich.edu                       unsigned flags, uint64_t *res);
6104224Sgblack@eecs.umich.edu
6114224Sgblack@eecs.umich.edutemplate
6124224Sgblack@eecs.umich.eduFault
6134224Sgblack@eecs.umich.eduTimingSimpleCPU::write(Twin64_t data, Addr addr,
6144224Sgblack@eecs.umich.edu                       unsigned flags, uint64_t *res);
6154224Sgblack@eecs.umich.edu
6164224Sgblack@eecs.umich.edutemplate
6174224Sgblack@eecs.umich.eduFault
6182623SN/ATimingSimpleCPU::write(uint64_t data, Addr addr,
6192623SN/A                       unsigned flags, uint64_t *res);
6202623SN/A
6212623SN/Atemplate
6222623SN/AFault
6232623SN/ATimingSimpleCPU::write(uint32_t data, Addr addr,
6242623SN/A                       unsigned flags, uint64_t *res);
6252623SN/A
6262623SN/Atemplate
6272623SN/AFault
6282623SN/ATimingSimpleCPU::write(uint16_t data, Addr addr,
6292623SN/A                       unsigned flags, uint64_t *res);
6302623SN/A
6312623SN/Atemplate
6322623SN/AFault
6332623SN/ATimingSimpleCPU::write(uint8_t data, Addr addr,
6342623SN/A                       unsigned flags, uint64_t *res);
6352623SN/A
6362623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
6372623SN/A
6382623SN/Atemplate<>
6392623SN/AFault
6402623SN/ATimingSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
6412623SN/A{
6422623SN/A    return write(*(uint64_t*)&data, addr, flags, res);
6432623SN/A}
6442623SN/A
6452623SN/Atemplate<>
6462623SN/AFault
6472623SN/ATimingSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
6482623SN/A{
6492623SN/A    return write(*(uint32_t*)&data, addr, flags, res);
6502623SN/A}
6512623SN/A
6522623SN/A
6532623SN/Atemplate<>
6542623SN/AFault
6552623SN/ATimingSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
6562623SN/A{
6572623SN/A    return write((uint32_t)data, addr, flags, res);
6582623SN/A}
6592623SN/A
6602623SN/A
6612623SN/Avoid
6622623SN/ATimingSimpleCPU::fetch()
6632623SN/A{
6645221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Fetch\n");
6655221Ssaidi@eecs.umich.edu
6663387Sgblack@eecs.umich.edu    if (!curStaticInst || !curStaticInst->isDelayedCommit())
6673387Sgblack@eecs.umich.edu        checkForInterrupts();
6682631SN/A
6695348Ssaidi@eecs.umich.edu    checkPcEventQueue();
6705348Ssaidi@eecs.umich.edu
6715669Sgblack@eecs.umich.edu    bool fromRom = isRomMicroPC(thread->readMicroPC());
6722623SN/A
6735914Sgblack@eecs.umich.edu    if (!fromRom && !curMacroStaticInst) {
6745669Sgblack@eecs.umich.edu        Request *ifetch_req = new Request();
6755712Shsul@eecs.umich.edu        ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0);
6765894Sgblack@eecs.umich.edu        setupFetchRequest(ifetch_req);
6776023Snate@binkert.org        thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation,
6786023Snate@binkert.org                BaseTLB::Execute);
6792623SN/A    } else {
6805669Sgblack@eecs.umich.edu        _status = IcacheWaitResponse;
6815669Sgblack@eecs.umich.edu        completeIfetch(NULL);
6825894Sgblack@eecs.umich.edu
6835894Sgblack@eecs.umich.edu        numCycles += tickToCycles(curTick - previousTick);
6845894Sgblack@eecs.umich.edu        previousTick = curTick;
6855894Sgblack@eecs.umich.edu    }
6865894Sgblack@eecs.umich.edu}
6875894Sgblack@eecs.umich.edu
6885894Sgblack@eecs.umich.edu
6895894Sgblack@eecs.umich.eduvoid
6905894Sgblack@eecs.umich.eduTimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc)
6915894Sgblack@eecs.umich.edu{
6925894Sgblack@eecs.umich.edu    if (fault == NoFault) {
6935894Sgblack@eecs.umich.edu        ifetch_pkt = new Packet(req, MemCmd::ReadReq, Packet::Broadcast);
6945894Sgblack@eecs.umich.edu        ifetch_pkt->dataStatic(&inst);
6955894Sgblack@eecs.umich.edu
6965894Sgblack@eecs.umich.edu        if (!icachePort.sendTiming(ifetch_pkt)) {
6975894Sgblack@eecs.umich.edu            // Need to wait for retry
6985894Sgblack@eecs.umich.edu            _status = IcacheRetry;
6995894Sgblack@eecs.umich.edu        } else {
7005894Sgblack@eecs.umich.edu            // Need to wait for cache to respond
7015894Sgblack@eecs.umich.edu            _status = IcacheWaitResponse;
7025894Sgblack@eecs.umich.edu            // ownership of packet transferred to memory system
7035894Sgblack@eecs.umich.edu            ifetch_pkt = NULL;
7045894Sgblack@eecs.umich.edu        }
7055894Sgblack@eecs.umich.edu    } else {
7065894Sgblack@eecs.umich.edu        delete req;
7075894Sgblack@eecs.umich.edu        // fetch fault: advance directly to next instruction (fault handler)
7085894Sgblack@eecs.umich.edu        advanceInst(fault);
7092623SN/A    }
7103222Sktlim@umich.edu
7115099Ssaidi@eecs.umich.edu    numCycles += tickToCycles(curTick - previousTick);
7123222Sktlim@umich.edu    previousTick = curTick;
7132623SN/A}
7142623SN/A
7152623SN/A
7162623SN/Avoid
7172644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault)
7182623SN/A{
7195726Sgblack@eecs.umich.edu    if (fault != NoFault || !stayAtPC)
7205726Sgblack@eecs.umich.edu        advancePC(fault);
7212623SN/A
7222631SN/A    if (_status == Running) {
7232631SN/A        // kick off fetch of next instruction... callback from icache
7242631SN/A        // response will cause that instruction to be executed,
7252631SN/A        // keeping the CPU running.
7262631SN/A        fetch();
7272631SN/A    }
7282623SN/A}
7292623SN/A
7302623SN/A
7312623SN/Avoid
7323349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt)
7332623SN/A{
7345221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Complete ICache Fetch\n");
7355221Ssaidi@eecs.umich.edu
7362623SN/A    // received a response from the icache: execute the received
7372623SN/A    // instruction
7385669Sgblack@eecs.umich.edu
7395669Sgblack@eecs.umich.edu    assert(!pkt || !pkt->isError());
7402623SN/A    assert(_status == IcacheWaitResponse);
7412798Sktlim@umich.edu
7422623SN/A    _status = Running;
7432644Sstever@eecs.umich.edu
7445099Ssaidi@eecs.umich.edu    numCycles += tickToCycles(curTick - previousTick);
7453222Sktlim@umich.edu    previousTick = curTick;
7463222Sktlim@umich.edu
7472839Sktlim@umich.edu    if (getState() == SimObject::Draining) {
7485669Sgblack@eecs.umich.edu        if (pkt) {
7495669Sgblack@eecs.umich.edu            delete pkt->req;
7505669Sgblack@eecs.umich.edu            delete pkt;
7515669Sgblack@eecs.umich.edu        }
7523658Sktlim@umich.edu
7532839Sktlim@umich.edu        completeDrain();
7542798Sktlim@umich.edu        return;
7552798Sktlim@umich.edu    }
7562798Sktlim@umich.edu
7572623SN/A    preExecute();
7585726Sgblack@eecs.umich.edu    if (curStaticInst &&
7595726Sgblack@eecs.umich.edu            curStaticInst->isMemRef() && !curStaticInst->isDataPrefetch()) {
7602623SN/A        // load or store: just send to dcache
7612623SN/A        Fault fault = curStaticInst->initiateAcc(this, traceData);
7623170Sstever@eecs.umich.edu        if (_status != Running) {
7633170Sstever@eecs.umich.edu            // instruction will complete in dcache response callback
7645894Sgblack@eecs.umich.edu            assert(_status == DcacheWaitResponse ||
7655894Sgblack@eecs.umich.edu                    _status == DcacheRetry || DTBWaitResponse);
7663170Sstever@eecs.umich.edu            assert(fault == NoFault);
7672644Sstever@eecs.umich.edu        } else {
7685894Sgblack@eecs.umich.edu            if (fault != NoFault && traceData) {
7695001Sgblack@eecs.umich.edu                // If there was a fault, we shouldn't trace this instruction.
7705001Sgblack@eecs.umich.edu                delete traceData;
7715001Sgblack@eecs.umich.edu                traceData = NULL;
7723170Sstever@eecs.umich.edu            }
7734998Sgblack@eecs.umich.edu
7742644Sstever@eecs.umich.edu            postExecute();
7755103Ssaidi@eecs.umich.edu            // @todo remove me after debugging with legion done
7765103Ssaidi@eecs.umich.edu            if (curStaticInst && (!curStaticInst->isMicroop() ||
7775103Ssaidi@eecs.umich.edu                        curStaticInst->isFirstMicroop()))
7785103Ssaidi@eecs.umich.edu                instCnt++;
7792644Sstever@eecs.umich.edu            advanceInst(fault);
7802644Sstever@eecs.umich.edu        }
7815726Sgblack@eecs.umich.edu    } else if (curStaticInst) {
7822623SN/A        // non-memory instruction: execute completely now
7832623SN/A        Fault fault = curStaticInst->execute(this, traceData);
7844998Sgblack@eecs.umich.edu
7854998Sgblack@eecs.umich.edu        // keep an instruction count
7864998Sgblack@eecs.umich.edu        if (fault == NoFault)
7874998Sgblack@eecs.umich.edu            countInst();
7885001Sgblack@eecs.umich.edu        else if (traceData) {
7895001Sgblack@eecs.umich.edu            // If there was a fault, we shouldn't trace this instruction.
7905001Sgblack@eecs.umich.edu            delete traceData;
7915001Sgblack@eecs.umich.edu            traceData = NULL;
7925001Sgblack@eecs.umich.edu        }
7934998Sgblack@eecs.umich.edu
7942644Sstever@eecs.umich.edu        postExecute();
7955103Ssaidi@eecs.umich.edu        // @todo remove me after debugging with legion done
7965103Ssaidi@eecs.umich.edu        if (curStaticInst && (!curStaticInst->isMicroop() ||
7975103Ssaidi@eecs.umich.edu                    curStaticInst->isFirstMicroop()))
7985103Ssaidi@eecs.umich.edu            instCnt++;
7992644Sstever@eecs.umich.edu        advanceInst(fault);
8005726Sgblack@eecs.umich.edu    } else {
8015726Sgblack@eecs.umich.edu        advanceInst(NoFault);
8022623SN/A    }
8033658Sktlim@umich.edu
8045669Sgblack@eecs.umich.edu    if (pkt) {
8055669Sgblack@eecs.umich.edu        delete pkt->req;
8065669Sgblack@eecs.umich.edu        delete pkt;
8075669Sgblack@eecs.umich.edu    }
8082623SN/A}
8092623SN/A
8102948Ssaidi@eecs.umich.eduvoid
8112948Ssaidi@eecs.umich.eduTimingSimpleCPU::IcachePort::ITickEvent::process()
8122948Ssaidi@eecs.umich.edu{
8132948Ssaidi@eecs.umich.edu    cpu->completeIfetch(pkt);
8142948Ssaidi@eecs.umich.edu}
8152623SN/A
8162623SN/Abool
8173349Sbinkertn@umich.eduTimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt)
8182623SN/A{
8194986Ssaidi@eecs.umich.edu    if (pkt->isResponse() && !pkt->wasNacked()) {
8203310Srdreslin@umich.edu        // delay processing of returned data until next CPU clock edge
8214584Ssaidi@eecs.umich.edu        Tick next_tick = cpu->nextCycle(curTick);
8222948Ssaidi@eecs.umich.edu
8233495Sktlim@umich.edu        if (next_tick == curTick)
8243310Srdreslin@umich.edu            cpu->completeIfetch(pkt);
8253310Srdreslin@umich.edu        else
8263495Sktlim@umich.edu            tickEvent.schedule(pkt, next_tick);
8272948Ssaidi@eecs.umich.edu
8283310Srdreslin@umich.edu        return true;
8293310Srdreslin@umich.edu    }
8304870Sstever@eecs.umich.edu    else if (pkt->wasNacked()) {
8314433Ssaidi@eecs.umich.edu        assert(cpu->_status == IcacheWaitResponse);
8324433Ssaidi@eecs.umich.edu        pkt->reinitNacked();
8334433Ssaidi@eecs.umich.edu        if (!sendTiming(pkt)) {
8344433Ssaidi@eecs.umich.edu            cpu->_status = IcacheRetry;
8354433Ssaidi@eecs.umich.edu            cpu->ifetch_pkt = pkt;
8364433Ssaidi@eecs.umich.edu        }
8373310Srdreslin@umich.edu    }
8384433Ssaidi@eecs.umich.edu    //Snooping a Coherence Request, do nothing
8394433Ssaidi@eecs.umich.edu    return true;
8402623SN/A}
8412623SN/A
8422657Ssaidi@eecs.umich.eduvoid
8432623SN/ATimingSimpleCPU::IcachePort::recvRetry()
8442623SN/A{
8452623SN/A    // we shouldn't get a retry unless we have a packet that we're
8462623SN/A    // waiting to transmit
8472623SN/A    assert(cpu->ifetch_pkt != NULL);
8482623SN/A    assert(cpu->_status == IcacheRetry);
8493349Sbinkertn@umich.edu    PacketPtr tmp = cpu->ifetch_pkt;
8502657Ssaidi@eecs.umich.edu    if (sendTiming(tmp)) {
8512657Ssaidi@eecs.umich.edu        cpu->_status = IcacheWaitResponse;
8522657Ssaidi@eecs.umich.edu        cpu->ifetch_pkt = NULL;
8532657Ssaidi@eecs.umich.edu    }
8542623SN/A}
8552623SN/A
8562623SN/Avoid
8573349Sbinkertn@umich.eduTimingSimpleCPU::completeDataAccess(PacketPtr pkt)
8582623SN/A{
8592623SN/A    // received a response from the dcache: complete the load or store
8602623SN/A    // instruction
8614870Sstever@eecs.umich.edu    assert(!pkt->isError());
8622623SN/A
8635099Ssaidi@eecs.umich.edu    numCycles += tickToCycles(curTick - previousTick);
8643222Sktlim@umich.edu    previousTick = curTick;
8653184Srdreslin@umich.edu
8665728Sgblack@eecs.umich.edu    if (pkt->senderState) {
8675728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
8685728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
8695728Sgblack@eecs.umich.edu        assert(send_state);
8705728Sgblack@eecs.umich.edu        delete pkt->req;
8715728Sgblack@eecs.umich.edu        delete pkt;
8725728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
8735728Sgblack@eecs.umich.edu        delete send_state;
8745728Sgblack@eecs.umich.edu
8755728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
8765728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
8775728Sgblack@eecs.umich.edu        assert(main_send_state);
8785728Sgblack@eecs.umich.edu        // Record the fact that this packet is no longer outstanding.
8795728Sgblack@eecs.umich.edu        assert(main_send_state->outstanding != 0);
8805728Sgblack@eecs.umich.edu        main_send_state->outstanding--;
8815728Sgblack@eecs.umich.edu
8825728Sgblack@eecs.umich.edu        if (main_send_state->outstanding) {
8835728Sgblack@eecs.umich.edu            return;
8845728Sgblack@eecs.umich.edu        } else {
8855728Sgblack@eecs.umich.edu            delete main_send_state;
8865728Sgblack@eecs.umich.edu            big_pkt->senderState = NULL;
8875728Sgblack@eecs.umich.edu            pkt = big_pkt;
8885728Sgblack@eecs.umich.edu        }
8895728Sgblack@eecs.umich.edu    }
8905728Sgblack@eecs.umich.edu
8915894Sgblack@eecs.umich.edu    assert(_status == DcacheWaitResponse || _status == DTBWaitResponse);
8925728Sgblack@eecs.umich.edu    _status = Running;
8935728Sgblack@eecs.umich.edu
8942623SN/A    Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
8952623SN/A
8964998Sgblack@eecs.umich.edu    // keep an instruction count
8974998Sgblack@eecs.umich.edu    if (fault == NoFault)
8984998Sgblack@eecs.umich.edu        countInst();
8995001Sgblack@eecs.umich.edu    else if (traceData) {
9005001Sgblack@eecs.umich.edu        // If there was a fault, we shouldn't trace this instruction.
9015001Sgblack@eecs.umich.edu        delete traceData;
9025001Sgblack@eecs.umich.edu        traceData = NULL;
9035001Sgblack@eecs.umich.edu    }
9044998Sgblack@eecs.umich.edu
9055507Sstever@gmail.com    // the locked flag may be cleared on the response packet, so check
9065507Sstever@gmail.com    // pkt->req and not pkt to see if it was a load-locked
9076102Sgblack@eecs.umich.edu    if (pkt->isRead() && pkt->req->isLLSC()) {
9083170Sstever@eecs.umich.edu        TheISA::handleLockedRead(thread, pkt->req);
9093170Sstever@eecs.umich.edu    }
9103170Sstever@eecs.umich.edu
9112644Sstever@eecs.umich.edu    delete pkt->req;
9122644Sstever@eecs.umich.edu    delete pkt;
9132644Sstever@eecs.umich.edu
9143184Srdreslin@umich.edu    postExecute();
9153227Sktlim@umich.edu
9163201Shsul@eecs.umich.edu    if (getState() == SimObject::Draining) {
9173201Shsul@eecs.umich.edu        advancePC(fault);
9183201Shsul@eecs.umich.edu        completeDrain();
9193201Shsul@eecs.umich.edu
9203201Shsul@eecs.umich.edu        return;
9213201Shsul@eecs.umich.edu    }
9223201Shsul@eecs.umich.edu
9232644Sstever@eecs.umich.edu    advanceInst(fault);
9242623SN/A}
9252623SN/A
9262623SN/A
9272798Sktlim@umich.eduvoid
9282839Sktlim@umich.eduTimingSimpleCPU::completeDrain()
9292798Sktlim@umich.edu{
9302839Sktlim@umich.edu    DPRINTF(Config, "Done draining\n");
9312901Ssaidi@eecs.umich.edu    changeState(SimObject::Drained);
9322839Sktlim@umich.edu    drainEvent->process();
9332798Sktlim@umich.edu}
9342623SN/A
9354192Sktlim@umich.eduvoid
9364192Sktlim@umich.eduTimingSimpleCPU::DcachePort::setPeer(Port *port)
9374192Sktlim@umich.edu{
9384192Sktlim@umich.edu    Port::setPeer(port);
9394192Sktlim@umich.edu
9404192Sktlim@umich.edu#if FULL_SYSTEM
9414192Sktlim@umich.edu    // Update the ThreadContext's memory ports (Functional/Virtual
9424192Sktlim@umich.edu    // Ports)
9435497Ssaidi@eecs.umich.edu    cpu->tcBase()->connectMemPorts(cpu->tcBase());
9444192Sktlim@umich.edu#endif
9454192Sktlim@umich.edu}
9464192Sktlim@umich.edu
9472623SN/Abool
9483349Sbinkertn@umich.eduTimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt)
9492623SN/A{
9504986Ssaidi@eecs.umich.edu    if (pkt->isResponse() && !pkt->wasNacked()) {
9513310Srdreslin@umich.edu        // delay processing of returned data until next CPU clock edge
9524584Ssaidi@eecs.umich.edu        Tick next_tick = cpu->nextCycle(curTick);
9532948Ssaidi@eecs.umich.edu
9545728Sgblack@eecs.umich.edu        if (next_tick == curTick) {
9553310Srdreslin@umich.edu            cpu->completeDataAccess(pkt);
9565728Sgblack@eecs.umich.edu        } else {
9573495Sktlim@umich.edu            tickEvent.schedule(pkt, next_tick);
9585728Sgblack@eecs.umich.edu        }
9592948Ssaidi@eecs.umich.edu
9603310Srdreslin@umich.edu        return true;
9613310Srdreslin@umich.edu    }
9624870Sstever@eecs.umich.edu    else if (pkt->wasNacked()) {
9634433Ssaidi@eecs.umich.edu        assert(cpu->_status == DcacheWaitResponse);
9644433Ssaidi@eecs.umich.edu        pkt->reinitNacked();
9654433Ssaidi@eecs.umich.edu        if (!sendTiming(pkt)) {
9664433Ssaidi@eecs.umich.edu            cpu->_status = DcacheRetry;
9674433Ssaidi@eecs.umich.edu            cpu->dcache_pkt = pkt;
9684433Ssaidi@eecs.umich.edu        }
9693310Srdreslin@umich.edu    }
9704433Ssaidi@eecs.umich.edu    //Snooping a Coherence Request, do nothing
9714433Ssaidi@eecs.umich.edu    return true;
9722948Ssaidi@eecs.umich.edu}
9732948Ssaidi@eecs.umich.edu
9742948Ssaidi@eecs.umich.eduvoid
9752948Ssaidi@eecs.umich.eduTimingSimpleCPU::DcachePort::DTickEvent::process()
9762948Ssaidi@eecs.umich.edu{
9772630SN/A    cpu->completeDataAccess(pkt);
9782623SN/A}
9792623SN/A
9802657Ssaidi@eecs.umich.eduvoid
9812623SN/ATimingSimpleCPU::DcachePort::recvRetry()
9822623SN/A{
9832623SN/A    // we shouldn't get a retry unless we have a packet that we're
9842623SN/A    // waiting to transmit
9852623SN/A    assert(cpu->dcache_pkt != NULL);
9862623SN/A    assert(cpu->_status == DcacheRetry);
9873349Sbinkertn@umich.edu    PacketPtr tmp = cpu->dcache_pkt;
9885728Sgblack@eecs.umich.edu    if (tmp->senderState) {
9895728Sgblack@eecs.umich.edu        // This is a packet from a split access.
9905728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
9915728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(tmp->senderState);
9925728Sgblack@eecs.umich.edu        assert(send_state);
9935728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
9945728Sgblack@eecs.umich.edu
9955728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
9965728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
9975728Sgblack@eecs.umich.edu        assert(main_send_state);
9985728Sgblack@eecs.umich.edu
9995728Sgblack@eecs.umich.edu        if (sendTiming(tmp)) {
10005728Sgblack@eecs.umich.edu            // If we were able to send without retrying, record that fact
10015728Sgblack@eecs.umich.edu            // and try sending the other fragment.
10025728Sgblack@eecs.umich.edu            send_state->clearFromParent();
10035728Sgblack@eecs.umich.edu            int other_index = main_send_state->getPendingFragment();
10045728Sgblack@eecs.umich.edu            if (other_index > 0) {
10055728Sgblack@eecs.umich.edu                tmp = main_send_state->fragments[other_index];
10065728Sgblack@eecs.umich.edu                cpu->dcache_pkt = tmp;
10075728Sgblack@eecs.umich.edu                if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) ||
10085728Sgblack@eecs.umich.edu                        (big_pkt->isWrite() && cpu->handleWritePacket())) {
10095728Sgblack@eecs.umich.edu                    main_send_state->fragments[other_index] = NULL;
10105728Sgblack@eecs.umich.edu                }
10115728Sgblack@eecs.umich.edu            } else {
10125728Sgblack@eecs.umich.edu                cpu->_status = DcacheWaitResponse;
10135728Sgblack@eecs.umich.edu                // memory system takes ownership of packet
10145728Sgblack@eecs.umich.edu                cpu->dcache_pkt = NULL;
10155728Sgblack@eecs.umich.edu            }
10165728Sgblack@eecs.umich.edu        }
10175728Sgblack@eecs.umich.edu    } else if (sendTiming(tmp)) {
10182657Ssaidi@eecs.umich.edu        cpu->_status = DcacheWaitResponse;
10193170Sstever@eecs.umich.edu        // memory system takes ownership of packet
10202657Ssaidi@eecs.umich.edu        cpu->dcache_pkt = NULL;
10212657Ssaidi@eecs.umich.edu    }
10222623SN/A}
10232623SN/A
10245606Snate@binkert.orgTimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu,
10255606Snate@binkert.org    Tick t)
10265606Snate@binkert.org    : pkt(_pkt), cpu(_cpu)
10275103Ssaidi@eecs.umich.edu{
10285606Snate@binkert.org    cpu->schedule(this, t);
10295103Ssaidi@eecs.umich.edu}
10305103Ssaidi@eecs.umich.edu
10315103Ssaidi@eecs.umich.eduvoid
10325103Ssaidi@eecs.umich.eduTimingSimpleCPU::IprEvent::process()
10335103Ssaidi@eecs.umich.edu{
10345103Ssaidi@eecs.umich.edu    cpu->completeDataAccess(pkt);
10355103Ssaidi@eecs.umich.edu}
10365103Ssaidi@eecs.umich.edu
10375103Ssaidi@eecs.umich.educonst char *
10385336Shines@cs.fsu.eduTimingSimpleCPU::IprEvent::description() const
10395103Ssaidi@eecs.umich.edu{
10405103Ssaidi@eecs.umich.edu    return "Timing Simple CPU Delay IPR event";
10415103Ssaidi@eecs.umich.edu}
10425103Ssaidi@eecs.umich.edu
10432623SN/A
10445315Sstever@gmail.comvoid
10455315Sstever@gmail.comTimingSimpleCPU::printAddr(Addr a)
10465315Sstever@gmail.com{
10475315Sstever@gmail.com    dcachePort.printAddr(a);
10485315Sstever@gmail.com}
10495315Sstever@gmail.com
10505315Sstever@gmail.com
10512623SN/A////////////////////////////////////////////////////////////////////////
10522623SN/A//
10532623SN/A//  TimingSimpleCPU Simulation Object
10542623SN/A//
10554762Snate@binkert.orgTimingSimpleCPU *
10564762Snate@binkert.orgTimingSimpleCPUParams::create()
10572623SN/A{
10585529Snate@binkert.org    numThreads = 1;
10595529Snate@binkert.org#if !FULL_SYSTEM
10604762Snate@binkert.org    if (workload.size() != 1)
10614762Snate@binkert.org        panic("only one workload allowed");
10622623SN/A#endif
10635529Snate@binkert.org    return new TimingSimpleCPU(this);
10642623SN/A}
1065