timing.cc revision 8948
12623SN/A/*
28948Sandreas.hansson@arm.com * Copyright (c) 2010-2012 ARM Limited
37725SAli.Saidi@ARM.com * All rights reserved
47725SAli.Saidi@ARM.com *
57725SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67725SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77725SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87725SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97725SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
107725SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117725SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127725SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137725SAli.Saidi@ARM.com *
142623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
152623SN/A * All rights reserved.
162623SN/A *
172623SN/A * Redistribution and use in source and binary forms, with or without
182623SN/A * modification, are permitted provided that the following conditions are
192623SN/A * met: redistributions of source code must retain the above copyright
202623SN/A * notice, this list of conditions and the following disclaimer;
212623SN/A * redistributions in binary form must reproduce the above copyright
222623SN/A * notice, this list of conditions and the following disclaimer in the
232623SN/A * documentation and/or other materials provided with the distribution;
242623SN/A * neither the name of the copyright holders nor the names of its
252623SN/A * contributors may be used to endorse or promote products derived from
262623SN/A * this software without specific prior written permission.
272623SN/A *
282623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
412623SN/A */
422623SN/A
433170Sstever@eecs.umich.edu#include "arch/locked_mem.hh"
448105Sgblack@eecs.umich.edu#include "arch/mmapped_ipr.hh"
452623SN/A#include "arch/utility.hh"
464040Ssaidi@eecs.umich.edu#include "base/bigint.hh"
476658Snate@binkert.org#include "config/the_isa.hh"
488229Snate@binkert.org#include "cpu/simple/timing.hh"
492623SN/A#include "cpu/exetrace.hh"
508232Snate@binkert.org#include "debug/Config.hh"
518232Snate@binkert.org#include "debug/ExecFaulting.hh"
528232Snate@binkert.org#include "debug/SimpleCPU.hh"
533348Sbinkertn@umich.edu#include "mem/packet.hh"
543348Sbinkertn@umich.edu#include "mem/packet_access.hh"
554762Snate@binkert.org#include "params/TimingSimpleCPU.hh"
567678Sgblack@eecs.umich.edu#include "sim/faults.hh"
578779Sgblack@eecs.umich.edu#include "sim/full_system.hh"
582901Ssaidi@eecs.umich.edu#include "sim/system.hh"
592623SN/A
602623SN/Ausing namespace std;
612623SN/Ausing namespace TheISA;
622623SN/A
632623SN/Avoid
642623SN/ATimingSimpleCPU::init()
652623SN/A{
662623SN/A    BaseCPU::init();
678921Sandreas.hansson@arm.com
688921Sandreas.hansson@arm.com    // Initialise the ThreadContext's memory proxies
698921Sandreas.hansson@arm.com    tcBase()->initMemProxies(tcBase());
708921Sandreas.hansson@arm.com
718779Sgblack@eecs.umich.edu    if (FullSystem) {
728779Sgblack@eecs.umich.edu        for (int i = 0; i < threadContexts.size(); ++i) {
738779Sgblack@eecs.umich.edu            ThreadContext *tc = threadContexts[i];
748779Sgblack@eecs.umich.edu            // initialize CPU, including PC
758779Sgblack@eecs.umich.edu            TheISA::initCPU(tc, _cpuId);
768779Sgblack@eecs.umich.edu        }
772623SN/A    }
782623SN/A}
792623SN/A
802623SN/Avoid
818707Sandreas.hansson@arm.comTimingSimpleCPU::TimingCPUPort::TickEvent::schedule(PacketPtr _pkt, Tick t)
822948Ssaidi@eecs.umich.edu{
832948Ssaidi@eecs.umich.edu    pkt = _pkt;
845606Snate@binkert.org    cpu->schedule(this, t);
852948Ssaidi@eecs.umich.edu}
862948Ssaidi@eecs.umich.edu
875529Snate@binkert.orgTimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p)
888707Sandreas.hansson@arm.com    : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this),
898707Sandreas.hansson@arm.com    dcachePort(this), fetchEvent(this)
902623SN/A{
912623SN/A    _status = Idle;
923647Srdreslin@umich.edu
932623SN/A    ifetch_pkt = dcache_pkt = NULL;
942839Sktlim@umich.edu    drainEvent = NULL;
953222Sktlim@umich.edu    previousTick = 0;
962901Ssaidi@eecs.umich.edu    changeState(SimObject::Running);
977897Shestness@cs.utexas.edu    system->totalNumInsts = 0;
982623SN/A}
992623SN/A
1002623SN/A
1012623SN/ATimingSimpleCPU::~TimingSimpleCPU()
1022623SN/A{
1032623SN/A}
1042623SN/A
1052623SN/Avoid
1062623SN/ATimingSimpleCPU::serialize(ostream &os)
1072623SN/A{
1082915Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
1092915Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
1102623SN/A    BaseSimpleCPU::serialize(os);
1112623SN/A}
1122623SN/A
1132623SN/Avoid
1142623SN/ATimingSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1152623SN/A{
1162915Sktlim@umich.edu    SimObject::State so_state;
1172915Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
1182623SN/A    BaseSimpleCPU::unserialize(cp, section);
1192798Sktlim@umich.edu}
1202798Sktlim@umich.edu
1212901Ssaidi@eecs.umich.eduunsigned int
1222839Sktlim@umich.eduTimingSimpleCPU::drain(Event *drain_event)
1232798Sktlim@umich.edu{
1242839Sktlim@umich.edu    // TimingSimpleCPU is ready to drain if it's not waiting for
1252798Sktlim@umich.edu    // an access to complete.
1265496Ssaidi@eecs.umich.edu    if (_status == Idle || _status == Running || _status == SwitchedOut) {
1272901Ssaidi@eecs.umich.edu        changeState(SimObject::Drained);
1282901Ssaidi@eecs.umich.edu        return 0;
1292798Sktlim@umich.edu    } else {
1302839Sktlim@umich.edu        changeState(SimObject::Draining);
1312839Sktlim@umich.edu        drainEvent = drain_event;
1322901Ssaidi@eecs.umich.edu        return 1;
1332798Sktlim@umich.edu    }
1342623SN/A}
1352623SN/A
1362623SN/Avoid
1372798Sktlim@umich.eduTimingSimpleCPU::resume()
1382623SN/A{
1395221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Resume\n");
1402798Sktlim@umich.edu    if (_status != SwitchedOut && _status != Idle) {
1414762Snate@binkert.org        assert(system->getMemoryMode() == Enums::timing);
1423201Shsul@eecs.umich.edu
1435710Scws3k@cs.virginia.edu        if (fetchEvent.scheduled())
1445710Scws3k@cs.virginia.edu           deschedule(fetchEvent);
1452915Sktlim@umich.edu
1465710Scws3k@cs.virginia.edu        schedule(fetchEvent, nextCycle());
1472623SN/A    }
1482798Sktlim@umich.edu
1492901Ssaidi@eecs.umich.edu    changeState(SimObject::Running);
1502798Sktlim@umich.edu}
1512798Sktlim@umich.edu
1522798Sktlim@umich.eduvoid
1532798Sktlim@umich.eduTimingSimpleCPU::switchOut()
1542798Sktlim@umich.edu{
1555496Ssaidi@eecs.umich.edu    assert(_status == Running || _status == Idle);
1562798Sktlim@umich.edu    _status = SwitchedOut;
1577823Ssteve.reinhardt@amd.com    numCycles += tickToCycles(curTick() - previousTick);
1582867Sktlim@umich.edu
1592867Sktlim@umich.edu    // If we've been scheduled to resume but are then told to switch out,
1602867Sktlim@umich.edu    // we'll need to cancel it.
1615710Scws3k@cs.virginia.edu    if (fetchEvent.scheduled())
1625606Snate@binkert.org        deschedule(fetchEvent);
1632623SN/A}
1642623SN/A
1652623SN/A
1662623SN/Avoid
1672623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
1682623SN/A{
1698737Skoansin.tan@gmail.com    BaseCPU::takeOverFrom(oldCPU);
1702623SN/A
1712680Sktlim@umich.edu    // if any of this CPU's ThreadContexts are active, mark the CPU as
1722623SN/A    // running and schedule its tick event.
1732680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
1742680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
1752680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
1762623SN/A            _status = Running;
1772623SN/A            break;
1782623SN/A        }
1792623SN/A    }
1803201Shsul@eecs.umich.edu
1813201Shsul@eecs.umich.edu    if (_status != Running) {
1823201Shsul@eecs.umich.edu        _status = Idle;
1833201Shsul@eecs.umich.edu    }
1845169Ssaidi@eecs.umich.edu    assert(threadContexts.size() == 1);
1857823Ssteve.reinhardt@amd.com    previousTick = curTick();
1862623SN/A}
1872623SN/A
1882623SN/A
1892623SN/Avoid
1908737Skoansin.tan@gmail.comTimingSimpleCPU::activateContext(ThreadID thread_num, int delay)
1912623SN/A{
1925221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay);
1935221Ssaidi@eecs.umich.edu
1942623SN/A    assert(thread_num == 0);
1952683Sktlim@umich.edu    assert(thread);
1962623SN/A
1972623SN/A    assert(_status == Idle);
1982623SN/A
1992623SN/A    notIdleFraction++;
2002623SN/A    _status = Running;
2013686Sktlim@umich.edu
2022623SN/A    // kick things off by initiating the fetch of the next instruction
2037823Ssteve.reinhardt@amd.com    schedule(fetchEvent, nextCycle(curTick() + ticks(delay)));
2042623SN/A}
2052623SN/A
2062623SN/A
2072623SN/Avoid
2088737Skoansin.tan@gmail.comTimingSimpleCPU::suspendContext(ThreadID thread_num)
2092623SN/A{
2105221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
2115221Ssaidi@eecs.umich.edu
2122623SN/A    assert(thread_num == 0);
2132683Sktlim@umich.edu    assert(thread);
2142623SN/A
2156043Sgblack@eecs.umich.edu    if (_status == Idle)
2166043Sgblack@eecs.umich.edu        return;
2176043Sgblack@eecs.umich.edu
2182644Sstever@eecs.umich.edu    assert(_status == Running);
2192623SN/A
2202644Sstever@eecs.umich.edu    // just change status to Idle... if status != Running,
2212644Sstever@eecs.umich.edu    // completeInst() will not initiate fetch of next instruction.
2222623SN/A
2232623SN/A    notIdleFraction--;
2242623SN/A    _status = Idle;
2252623SN/A}
2262623SN/A
2275728Sgblack@eecs.umich.edubool
2285728Sgblack@eecs.umich.eduTimingSimpleCPU::handleReadPacket(PacketPtr pkt)
2295728Sgblack@eecs.umich.edu{
2305728Sgblack@eecs.umich.edu    RequestPtr req = pkt->req;
2318105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
2325728Sgblack@eecs.umich.edu        Tick delay;
2335728Sgblack@eecs.umich.edu        delay = TheISA::handleIprRead(thread->getTC(), pkt);
2347823Ssteve.reinhardt@amd.com        new IprEvent(pkt, this, nextCycle(curTick() + delay));
2355728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2365728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2375728Sgblack@eecs.umich.edu    } else if (!dcachePort.sendTiming(pkt)) {
2385728Sgblack@eecs.umich.edu        _status = DcacheRetry;
2395728Sgblack@eecs.umich.edu        dcache_pkt = pkt;
2405728Sgblack@eecs.umich.edu    } else {
2415728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2425728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
2435728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2445728Sgblack@eecs.umich.edu    }
2455728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
2465728Sgblack@eecs.umich.edu}
2472623SN/A
2485894Sgblack@eecs.umich.eduvoid
2496973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
2506973Stjones1@inf.ed.ac.uk                          bool read)
2515744Sgblack@eecs.umich.edu{
2525894Sgblack@eecs.umich.edu    PacketPtr pkt;
2535894Sgblack@eecs.umich.edu    buildPacket(pkt, req, read);
2547691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
2555894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2565894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2575894Sgblack@eecs.umich.edu        pkt->makeResponse();
2585894Sgblack@eecs.umich.edu        completeDataAccess(pkt);
2595894Sgblack@eecs.umich.edu    } else if (read) {
2605894Sgblack@eecs.umich.edu        handleReadPacket(pkt);
2615894Sgblack@eecs.umich.edu    } else {
2625894Sgblack@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
2635894Sgblack@eecs.umich.edu
2646102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
2655894Sgblack@eecs.umich.edu            do_access = TheISA::handleLockedWrite(thread, req);
2665894Sgblack@eecs.umich.edu        } else if (req->isCondSwap()) {
2675894Sgblack@eecs.umich.edu            assert(res);
2685894Sgblack@eecs.umich.edu            req->setExtraData(*res);
2695894Sgblack@eecs.umich.edu        }
2705894Sgblack@eecs.umich.edu
2715894Sgblack@eecs.umich.edu        if (do_access) {
2725894Sgblack@eecs.umich.edu            dcache_pkt = pkt;
2735894Sgblack@eecs.umich.edu            handleWritePacket();
2745894Sgblack@eecs.umich.edu        } else {
2755894Sgblack@eecs.umich.edu            _status = DcacheWaitResponse;
2765894Sgblack@eecs.umich.edu            completeDataAccess(pkt);
2775894Sgblack@eecs.umich.edu        }
2785894Sgblack@eecs.umich.edu    }
2795894Sgblack@eecs.umich.edu}
2805894Sgblack@eecs.umich.edu
2815894Sgblack@eecs.umich.eduvoid
2826973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendSplitData(RequestPtr req1, RequestPtr req2,
2836973Stjones1@inf.ed.ac.uk                               RequestPtr req, uint8_t *data, bool read)
2845894Sgblack@eecs.umich.edu{
2855894Sgblack@eecs.umich.edu    PacketPtr pkt1, pkt2;
2865894Sgblack@eecs.umich.edu    buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
2875894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2885894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2895894Sgblack@eecs.umich.edu        pkt1->makeResponse();
2905894Sgblack@eecs.umich.edu        completeDataAccess(pkt1);
2915894Sgblack@eecs.umich.edu    } else if (read) {
2927911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
2937911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
2945894Sgblack@eecs.umich.edu        if (handleReadPacket(pkt1)) {
2955894Sgblack@eecs.umich.edu            send_state->clearFromParent();
2967911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
2977911Shestness@cs.utexas.edu                    pkt2->senderState);
2985894Sgblack@eecs.umich.edu            if (handleReadPacket(pkt2)) {
2995894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3005894Sgblack@eecs.umich.edu            }
3015894Sgblack@eecs.umich.edu        }
3025894Sgblack@eecs.umich.edu    } else {
3035894Sgblack@eecs.umich.edu        dcache_pkt = pkt1;
3047911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
3057911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3065894Sgblack@eecs.umich.edu        if (handleWritePacket()) {
3075894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3085894Sgblack@eecs.umich.edu            dcache_pkt = pkt2;
3097911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
3107911Shestness@cs.utexas.edu                    pkt2->senderState);
3115894Sgblack@eecs.umich.edu            if (handleWritePacket()) {
3125894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3135894Sgblack@eecs.umich.edu            }
3145894Sgblack@eecs.umich.edu        }
3155894Sgblack@eecs.umich.edu    }
3165894Sgblack@eecs.umich.edu}
3175894Sgblack@eecs.umich.edu
3185894Sgblack@eecs.umich.eduvoid
3195894Sgblack@eecs.umich.eduTimingSimpleCPU::translationFault(Fault fault)
3205894Sgblack@eecs.umich.edu{
3216739Sgblack@eecs.umich.edu    // fault may be NoFault in cases where a fault is suppressed,
3226739Sgblack@eecs.umich.edu    // for instance prefetches.
3237823Ssteve.reinhardt@amd.com    numCycles += tickToCycles(curTick() - previousTick);
3247823Ssteve.reinhardt@amd.com    previousTick = curTick();
3255894Sgblack@eecs.umich.edu
3265894Sgblack@eecs.umich.edu    if (traceData) {
3275894Sgblack@eecs.umich.edu        // Since there was a fault, we shouldn't trace this instruction.
3285894Sgblack@eecs.umich.edu        delete traceData;
3295894Sgblack@eecs.umich.edu        traceData = NULL;
3305744Sgblack@eecs.umich.edu    }
3315744Sgblack@eecs.umich.edu
3325894Sgblack@eecs.umich.edu    postExecute();
3335894Sgblack@eecs.umich.edu
3345894Sgblack@eecs.umich.edu    if (getState() == SimObject::Draining) {
3355894Sgblack@eecs.umich.edu        advancePC(fault);
3365894Sgblack@eecs.umich.edu        completeDrain();
3375894Sgblack@eecs.umich.edu    } else {
3385894Sgblack@eecs.umich.edu        advanceInst(fault);
3395894Sgblack@eecs.umich.edu    }
3405894Sgblack@eecs.umich.edu}
3415894Sgblack@eecs.umich.edu
3425894Sgblack@eecs.umich.eduvoid
3435894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
3445894Sgblack@eecs.umich.edu{
3455894Sgblack@eecs.umich.edu    MemCmd cmd;
3465894Sgblack@eecs.umich.edu    if (read) {
3475894Sgblack@eecs.umich.edu        cmd = MemCmd::ReadReq;
3486102Sgblack@eecs.umich.edu        if (req->isLLSC())
3495894Sgblack@eecs.umich.edu            cmd = MemCmd::LoadLockedReq;
3505894Sgblack@eecs.umich.edu    } else {
3515894Sgblack@eecs.umich.edu        cmd = MemCmd::WriteReq;
3526102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
3535894Sgblack@eecs.umich.edu            cmd = MemCmd::StoreCondReq;
3545894Sgblack@eecs.umich.edu        } else if (req->isSwap()) {
3555894Sgblack@eecs.umich.edu            cmd = MemCmd::SwapReq;
3565894Sgblack@eecs.umich.edu        }
3575894Sgblack@eecs.umich.edu    }
3585894Sgblack@eecs.umich.edu    pkt = new Packet(req, cmd, Packet::Broadcast);
3595894Sgblack@eecs.umich.edu}
3605894Sgblack@eecs.umich.edu
3615894Sgblack@eecs.umich.eduvoid
3625894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
3635894Sgblack@eecs.umich.edu        RequestPtr req1, RequestPtr req2, RequestPtr req,
3645894Sgblack@eecs.umich.edu        uint8_t *data, bool read)
3655894Sgblack@eecs.umich.edu{
3665894Sgblack@eecs.umich.edu    pkt1 = pkt2 = NULL;
3675894Sgblack@eecs.umich.edu
3688105Sgblack@eecs.umich.edu    assert(!req1->isMmappedIpr() && !req2->isMmappedIpr());
3695744Sgblack@eecs.umich.edu
3705894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3715894Sgblack@eecs.umich.edu        buildPacket(pkt1, req, read);
3725894Sgblack@eecs.umich.edu        return;
3735894Sgblack@eecs.umich.edu    }
3745894Sgblack@eecs.umich.edu
3755894Sgblack@eecs.umich.edu    buildPacket(pkt1, req1, read);
3765894Sgblack@eecs.umich.edu    buildPacket(pkt2, req2, read);
3775894Sgblack@eecs.umich.edu
3788832SAli.Saidi@ARM.com    req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags(), dataMasterId());
3795744Sgblack@eecs.umich.edu    PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand(),
3805744Sgblack@eecs.umich.edu                               Packet::Broadcast);
3815744Sgblack@eecs.umich.edu
3827691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
3835744Sgblack@eecs.umich.edu    pkt1->dataStatic<uint8_t>(data);
3845744Sgblack@eecs.umich.edu    pkt2->dataStatic<uint8_t>(data + req1->getSize());
3855744Sgblack@eecs.umich.edu
3865744Sgblack@eecs.umich.edu    SplitMainSenderState * main_send_state = new SplitMainSenderState;
3875744Sgblack@eecs.umich.edu    pkt->senderState = main_send_state;
3885744Sgblack@eecs.umich.edu    main_send_state->fragments[0] = pkt1;
3895744Sgblack@eecs.umich.edu    main_send_state->fragments[1] = pkt2;
3905744Sgblack@eecs.umich.edu    main_send_state->outstanding = 2;
3915744Sgblack@eecs.umich.edu    pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
3925744Sgblack@eecs.umich.edu    pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
3935744Sgblack@eecs.umich.edu}
3945744Sgblack@eecs.umich.edu
3952623SN/AFault
3968444Sgblack@eecs.umich.eduTimingSimpleCPU::readMem(Addr addr, uint8_t *data,
3978444Sgblack@eecs.umich.edu                         unsigned size, unsigned flags)
3982623SN/A{
3995728Sgblack@eecs.umich.edu    Fault fault;
4005728Sgblack@eecs.umich.edu    const int asid = 0;
4016221Snate@binkert.org    const ThreadID tid = 0;
4027720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4036227Snate@binkert.org    unsigned block_size = dcachePort.peerBlockSize();
4046973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Read;
4052623SN/A
4067045Ssteve.reinhardt@amd.com    if (traceData) {
4077045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4087045Ssteve.reinhardt@amd.com    }
4097045Ssteve.reinhardt@amd.com
4107520Sgblack@eecs.umich.edu    RequestPtr req  = new Request(asid, addr, size,
4118832SAli.Saidi@ARM.com                                  flags, dataMasterId(), pc, _cpuId, tid);
4125728Sgblack@eecs.umich.edu
4137520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4145744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4155728Sgblack@eecs.umich.edu
4165894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4175744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4185894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4196102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4205894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4215894Sgblack@eecs.umich.edu
4226973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4237520Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, new uint8_t[size],
4246973Stjones1@inf.ed.ac.uk                                      NULL, mode);
4258486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4268486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4278486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
4288486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
4296973Stjones1@inf.ed.ac.uk
4306973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
4316973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
4325744Sgblack@eecs.umich.edu    } else {
4336973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4347520Sgblack@eecs.umich.edu            new WholeTranslationState(req, new uint8_t[size], NULL, mode);
4358486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation
4368486Sgblack@eecs.umich.edu            = new DataTranslation<TimingSimpleCPU *>(this, state);
4376973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
4382623SN/A    }
4392623SN/A
4405728Sgblack@eecs.umich.edu    return NoFault;
4412623SN/A}
4422623SN/A
4435728Sgblack@eecs.umich.edubool
4445728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket()
4455728Sgblack@eecs.umich.edu{
4465728Sgblack@eecs.umich.edu    RequestPtr req = dcache_pkt->req;
4478105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
4485728Sgblack@eecs.umich.edu        Tick delay;
4495728Sgblack@eecs.umich.edu        delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
4507823Ssteve.reinhardt@amd.com        new IprEvent(dcache_pkt, this, nextCycle(curTick() + delay));
4515728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4525728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4535728Sgblack@eecs.umich.edu    } else if (!dcachePort.sendTiming(dcache_pkt)) {
4545728Sgblack@eecs.umich.edu        _status = DcacheRetry;
4555728Sgblack@eecs.umich.edu    } else {
4565728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4575728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
4585728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4595728Sgblack@eecs.umich.edu    }
4605728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
4615728Sgblack@eecs.umich.edu}
4622623SN/A
4632623SN/AFault
4648444Sgblack@eecs.umich.eduTimingSimpleCPU::writeMem(uint8_t *data, unsigned size,
4658444Sgblack@eecs.umich.edu                          Addr addr, unsigned flags, uint64_t *res)
4662623SN/A{
4678443Sgblack@eecs.umich.edu    uint8_t *newData = new uint8_t[size];
4688443Sgblack@eecs.umich.edu    memcpy(newData, data, size);
4698443Sgblack@eecs.umich.edu
4705728Sgblack@eecs.umich.edu    const int asid = 0;
4716221Snate@binkert.org    const ThreadID tid = 0;
4727720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4736227Snate@binkert.org    unsigned block_size = dcachePort.peerBlockSize();
4746973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Write;
4753169Sstever@eecs.umich.edu
4767045Ssteve.reinhardt@amd.com    if (traceData) {
4777045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4787045Ssteve.reinhardt@amd.com    }
4797045Ssteve.reinhardt@amd.com
4807520Sgblack@eecs.umich.edu    RequestPtr req = new Request(asid, addr, size,
4818832SAli.Saidi@ARM.com                                 flags, dataMasterId(), pc, _cpuId, tid);
4825728Sgblack@eecs.umich.edu
4837520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4845744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4855728Sgblack@eecs.umich.edu
4865894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4875744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4885894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4896102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4905894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4915894Sgblack@eecs.umich.edu
4926973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4938443Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, newData, res, mode);
4948486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4958486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4968486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
4978486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
4986973Stjones1@inf.ed.ac.uk
4996973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
5006973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
5015744Sgblack@eecs.umich.edu    } else {
5026973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
5038443Sgblack@eecs.umich.edu            new WholeTranslationState(req, newData, res, mode);
5048486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation =
5058486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state);
5066973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
5072623SN/A    }
5082623SN/A
5097045Ssteve.reinhardt@amd.com    // Translation faults will be returned via finishTranslation()
5105728Sgblack@eecs.umich.edu    return NoFault;
5112623SN/A}
5122623SN/A
5132623SN/A
5142623SN/Avoid
5156973Stjones1@inf.ed.ac.ukTimingSimpleCPU::finishTranslation(WholeTranslationState *state)
5166973Stjones1@inf.ed.ac.uk{
5176973Stjones1@inf.ed.ac.uk    _status = Running;
5186973Stjones1@inf.ed.ac.uk
5196973Stjones1@inf.ed.ac.uk    if (state->getFault() != NoFault) {
5206973Stjones1@inf.ed.ac.uk        if (state->isPrefetch()) {
5216973Stjones1@inf.ed.ac.uk            state->setNoFault();
5226973Stjones1@inf.ed.ac.uk        }
5237691SAli.Saidi@ARM.com        delete [] state->data;
5246973Stjones1@inf.ed.ac.uk        state->deleteReqs();
5256973Stjones1@inf.ed.ac.uk        translationFault(state->getFault());
5266973Stjones1@inf.ed.ac.uk    } else {
5276973Stjones1@inf.ed.ac.uk        if (!state->isSplit) {
5286973Stjones1@inf.ed.ac.uk            sendData(state->mainReq, state->data, state->res,
5296973Stjones1@inf.ed.ac.uk                     state->mode == BaseTLB::Read);
5306973Stjones1@inf.ed.ac.uk        } else {
5316973Stjones1@inf.ed.ac.uk            sendSplitData(state->sreqLow, state->sreqHigh, state->mainReq,
5326973Stjones1@inf.ed.ac.uk                          state->data, state->mode == BaseTLB::Read);
5336973Stjones1@inf.ed.ac.uk        }
5346973Stjones1@inf.ed.ac.uk    }
5356973Stjones1@inf.ed.ac.uk
5366973Stjones1@inf.ed.ac.uk    delete state;
5376973Stjones1@inf.ed.ac.uk}
5386973Stjones1@inf.ed.ac.uk
5396973Stjones1@inf.ed.ac.uk
5406973Stjones1@inf.ed.ac.ukvoid
5412623SN/ATimingSimpleCPU::fetch()
5422623SN/A{
5435221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Fetch\n");
5445221Ssaidi@eecs.umich.edu
5453387Sgblack@eecs.umich.edu    if (!curStaticInst || !curStaticInst->isDelayedCommit())
5463387Sgblack@eecs.umich.edu        checkForInterrupts();
5472631SN/A
5485348Ssaidi@eecs.umich.edu    checkPcEventQueue();
5495348Ssaidi@eecs.umich.edu
5508143SAli.Saidi@ARM.com    // We must have just got suspended by a PC event
5518143SAli.Saidi@ARM.com    if (_status == Idle)
5528143SAli.Saidi@ARM.com        return;
5538143SAli.Saidi@ARM.com
5547720Sgblack@eecs.umich.edu    TheISA::PCState pcState = thread->pcState();
5557720Sgblack@eecs.umich.edu    bool needToFetch = !isRomMicroPC(pcState.microPC()) && !curMacroStaticInst;
5562623SN/A
5577720Sgblack@eecs.umich.edu    if (needToFetch) {
5588276SAli.Saidi@ARM.com        _status = Running;
5595669Sgblack@eecs.umich.edu        Request *ifetch_req = new Request();
5605712Shsul@eecs.umich.edu        ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0);
5615894Sgblack@eecs.umich.edu        setupFetchRequest(ifetch_req);
5628277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translating address %#x\n", ifetch_req->getVaddr());
5636023Snate@binkert.org        thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation,
5646023Snate@binkert.org                BaseTLB::Execute);
5652623SN/A    } else {
5665669Sgblack@eecs.umich.edu        _status = IcacheWaitResponse;
5675669Sgblack@eecs.umich.edu        completeIfetch(NULL);
5685894Sgblack@eecs.umich.edu
5697823Ssteve.reinhardt@amd.com        numCycles += tickToCycles(curTick() - previousTick);
5707823Ssteve.reinhardt@amd.com        previousTick = curTick();
5715894Sgblack@eecs.umich.edu    }
5725894Sgblack@eecs.umich.edu}
5735894Sgblack@eecs.umich.edu
5745894Sgblack@eecs.umich.edu
5755894Sgblack@eecs.umich.eduvoid
5765894Sgblack@eecs.umich.eduTimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc)
5775894Sgblack@eecs.umich.edu{
5785894Sgblack@eecs.umich.edu    if (fault == NoFault) {
5798277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Sending fetch for addr %#x(pa: %#x)\n",
5808277SAli.Saidi@ARM.com                req->getVaddr(), req->getPaddr());
5815894Sgblack@eecs.umich.edu        ifetch_pkt = new Packet(req, MemCmd::ReadReq, Packet::Broadcast);
5825894Sgblack@eecs.umich.edu        ifetch_pkt->dataStatic(&inst);
5838277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, " -- pkt addr: %#x\n", ifetch_pkt->getAddr());
5845894Sgblack@eecs.umich.edu
5855894Sgblack@eecs.umich.edu        if (!icachePort.sendTiming(ifetch_pkt)) {
5865894Sgblack@eecs.umich.edu            // Need to wait for retry
5875894Sgblack@eecs.umich.edu            _status = IcacheRetry;
5885894Sgblack@eecs.umich.edu        } else {
5895894Sgblack@eecs.umich.edu            // Need to wait for cache to respond
5905894Sgblack@eecs.umich.edu            _status = IcacheWaitResponse;
5915894Sgblack@eecs.umich.edu            // ownership of packet transferred to memory system
5925894Sgblack@eecs.umich.edu            ifetch_pkt = NULL;
5935894Sgblack@eecs.umich.edu        }
5945894Sgblack@eecs.umich.edu    } else {
5958277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translation of addr %#x faulted\n", req->getVaddr());
5965894Sgblack@eecs.umich.edu        delete req;
5975894Sgblack@eecs.umich.edu        // fetch fault: advance directly to next instruction (fault handler)
5987945SAli.Saidi@ARM.com        _status = Running;
5995894Sgblack@eecs.umich.edu        advanceInst(fault);
6002623SN/A    }
6013222Sktlim@umich.edu
6027823Ssteve.reinhardt@amd.com    numCycles += tickToCycles(curTick() - previousTick);
6037823Ssteve.reinhardt@amd.com    previousTick = curTick();
6042623SN/A}
6052623SN/A
6062623SN/A
6072623SN/Avoid
6082644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault)
6092623SN/A{
6108276SAli.Saidi@ARM.com
6118276SAli.Saidi@ARM.com    if (_status == Faulting)
6128276SAli.Saidi@ARM.com        return;
6138276SAli.Saidi@ARM.com
6148276SAli.Saidi@ARM.com    if (fault != NoFault) {
6158276SAli.Saidi@ARM.com        advancePC(fault);
6168276SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Fault occured, scheduling fetch event\n");
6178276SAli.Saidi@ARM.com        reschedule(fetchEvent, nextCycle(), true);
6188276SAli.Saidi@ARM.com        _status = Faulting;
6198276SAli.Saidi@ARM.com        return;
6208276SAli.Saidi@ARM.com    }
6218276SAli.Saidi@ARM.com
6228276SAli.Saidi@ARM.com
6238276SAli.Saidi@ARM.com    if (!stayAtPC)
6245726Sgblack@eecs.umich.edu        advancePC(fault);
6252623SN/A
6262631SN/A    if (_status == Running) {
6272631SN/A        // kick off fetch of next instruction... callback from icache
6282631SN/A        // response will cause that instruction to be executed,
6292631SN/A        // keeping the CPU running.
6302631SN/A        fetch();
6312631SN/A    }
6322623SN/A}
6332623SN/A
6342623SN/A
6352623SN/Avoid
6363349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt)
6372623SN/A{
6388277SAli.Saidi@ARM.com    DPRINTF(SimpleCPU, "Complete ICache Fetch for addr %#x\n", pkt ?
6398277SAli.Saidi@ARM.com            pkt->getAddr() : 0);
6408277SAli.Saidi@ARM.com
6412623SN/A    // received a response from the icache: execute the received
6422623SN/A    // instruction
6435669Sgblack@eecs.umich.edu
6445669Sgblack@eecs.umich.edu    assert(!pkt || !pkt->isError());
6452623SN/A    assert(_status == IcacheWaitResponse);
6462798Sktlim@umich.edu
6472623SN/A    _status = Running;
6482644Sstever@eecs.umich.edu
6497823Ssteve.reinhardt@amd.com    numCycles += tickToCycles(curTick() - previousTick);
6507823Ssteve.reinhardt@amd.com    previousTick = curTick();
6513222Sktlim@umich.edu
6522839Sktlim@umich.edu    if (getState() == SimObject::Draining) {
6535669Sgblack@eecs.umich.edu        if (pkt) {
6545669Sgblack@eecs.umich.edu            delete pkt->req;
6555669Sgblack@eecs.umich.edu            delete pkt;
6565669Sgblack@eecs.umich.edu        }
6573658Sktlim@umich.edu
6582839Sktlim@umich.edu        completeDrain();
6592798Sktlim@umich.edu        return;
6602798Sktlim@umich.edu    }
6612798Sktlim@umich.edu
6622623SN/A    preExecute();
6637725SAli.Saidi@ARM.com    if (curStaticInst && curStaticInst->isMemRef()) {
6642623SN/A        // load or store: just send to dcache
6652623SN/A        Fault fault = curStaticInst->initiateAcc(this, traceData);
6667945SAli.Saidi@ARM.com
6677945SAli.Saidi@ARM.com        // If we're not running now the instruction will complete in a dcache
6687945SAli.Saidi@ARM.com        // response callback or the instruction faulted and has started an
6697945SAli.Saidi@ARM.com        // ifetch
6707945SAli.Saidi@ARM.com        if (_status == Running) {
6715894Sgblack@eecs.umich.edu            if (fault != NoFault && traceData) {
6725001Sgblack@eecs.umich.edu                // If there was a fault, we shouldn't trace this instruction.
6735001Sgblack@eecs.umich.edu                delete traceData;
6745001Sgblack@eecs.umich.edu                traceData = NULL;
6753170Sstever@eecs.umich.edu            }
6764998Sgblack@eecs.umich.edu
6772644Sstever@eecs.umich.edu            postExecute();
6785103Ssaidi@eecs.umich.edu            // @todo remove me after debugging with legion done
6795103Ssaidi@eecs.umich.edu            if (curStaticInst && (!curStaticInst->isMicroop() ||
6805103Ssaidi@eecs.umich.edu                        curStaticInst->isFirstMicroop()))
6815103Ssaidi@eecs.umich.edu                instCnt++;
6822644Sstever@eecs.umich.edu            advanceInst(fault);
6832644Sstever@eecs.umich.edu        }
6845726Sgblack@eecs.umich.edu    } else if (curStaticInst) {
6852623SN/A        // non-memory instruction: execute completely now
6862623SN/A        Fault fault = curStaticInst->execute(this, traceData);
6874998Sgblack@eecs.umich.edu
6884998Sgblack@eecs.umich.edu        // keep an instruction count
6894998Sgblack@eecs.umich.edu        if (fault == NoFault)
6904998Sgblack@eecs.umich.edu            countInst();
6917655Sali.saidi@arm.com        else if (traceData && !DTRACE(ExecFaulting)) {
6925001Sgblack@eecs.umich.edu            delete traceData;
6935001Sgblack@eecs.umich.edu            traceData = NULL;
6945001Sgblack@eecs.umich.edu        }
6954998Sgblack@eecs.umich.edu
6962644Sstever@eecs.umich.edu        postExecute();
6975103Ssaidi@eecs.umich.edu        // @todo remove me after debugging with legion done
6985103Ssaidi@eecs.umich.edu        if (curStaticInst && (!curStaticInst->isMicroop() ||
6995103Ssaidi@eecs.umich.edu                    curStaticInst->isFirstMicroop()))
7005103Ssaidi@eecs.umich.edu            instCnt++;
7012644Sstever@eecs.umich.edu        advanceInst(fault);
7025726Sgblack@eecs.umich.edu    } else {
7035726Sgblack@eecs.umich.edu        advanceInst(NoFault);
7042623SN/A    }
7053658Sktlim@umich.edu
7065669Sgblack@eecs.umich.edu    if (pkt) {
7075669Sgblack@eecs.umich.edu        delete pkt->req;
7085669Sgblack@eecs.umich.edu        delete pkt;
7095669Sgblack@eecs.umich.edu    }
7102623SN/A}
7112623SN/A
7122948Ssaidi@eecs.umich.eduvoid
7132948Ssaidi@eecs.umich.eduTimingSimpleCPU::IcachePort::ITickEvent::process()
7142948Ssaidi@eecs.umich.edu{
7152948Ssaidi@eecs.umich.edu    cpu->completeIfetch(pkt);
7162948Ssaidi@eecs.umich.edu}
7172623SN/A
7182623SN/Abool
7193349Sbinkertn@umich.eduTimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt)
7202623SN/A{
7218948Sandreas.hansson@arm.com    assert(pkt->isResponse());
7228948Sandreas.hansson@arm.com    if (!pkt->wasNacked()) {
7238277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Received timing response %#x\n", pkt->getAddr());
7243310Srdreslin@umich.edu        // delay processing of returned data until next CPU clock edge
7257823Ssteve.reinhardt@amd.com        Tick next_tick = cpu->nextCycle(curTick());
7262948Ssaidi@eecs.umich.edu
7277823Ssteve.reinhardt@amd.com        if (next_tick == curTick())
7283310Srdreslin@umich.edu            cpu->completeIfetch(pkt);
7293310Srdreslin@umich.edu        else
7303495Sktlim@umich.edu            tickEvent.schedule(pkt, next_tick);
7312948Ssaidi@eecs.umich.edu
7323310Srdreslin@umich.edu        return true;
7338948Sandreas.hansson@arm.com    } else {
7344433Ssaidi@eecs.umich.edu        assert(cpu->_status == IcacheWaitResponse);
7354433Ssaidi@eecs.umich.edu        pkt->reinitNacked();
7364433Ssaidi@eecs.umich.edu        if (!sendTiming(pkt)) {
7374433Ssaidi@eecs.umich.edu            cpu->_status = IcacheRetry;
7384433Ssaidi@eecs.umich.edu            cpu->ifetch_pkt = pkt;
7394433Ssaidi@eecs.umich.edu        }
7403310Srdreslin@umich.edu    }
7418948Sandreas.hansson@arm.com
7424433Ssaidi@eecs.umich.edu    return true;
7432623SN/A}
7442623SN/A
7452657Ssaidi@eecs.umich.eduvoid
7462623SN/ATimingSimpleCPU::IcachePort::recvRetry()
7472623SN/A{
7482623SN/A    // we shouldn't get a retry unless we have a packet that we're
7492623SN/A    // waiting to transmit
7502623SN/A    assert(cpu->ifetch_pkt != NULL);
7512623SN/A    assert(cpu->_status == IcacheRetry);
7523349Sbinkertn@umich.edu    PacketPtr tmp = cpu->ifetch_pkt;
7532657Ssaidi@eecs.umich.edu    if (sendTiming(tmp)) {
7542657Ssaidi@eecs.umich.edu        cpu->_status = IcacheWaitResponse;
7552657Ssaidi@eecs.umich.edu        cpu->ifetch_pkt = NULL;
7562657Ssaidi@eecs.umich.edu    }
7572623SN/A}
7582623SN/A
7592623SN/Avoid
7603349Sbinkertn@umich.eduTimingSimpleCPU::completeDataAccess(PacketPtr pkt)
7612623SN/A{
7622623SN/A    // received a response from the dcache: complete the load or store
7632623SN/A    // instruction
7644870Sstever@eecs.umich.edu    assert(!pkt->isError());
7657516Shestness@cs.utexas.edu    assert(_status == DcacheWaitResponse || _status == DTBWaitResponse ||
7667516Shestness@cs.utexas.edu           pkt->req->getFlags().isSet(Request::NO_ACCESS));
7672623SN/A
7687823Ssteve.reinhardt@amd.com    numCycles += tickToCycles(curTick() - previousTick);
7697823Ssteve.reinhardt@amd.com    previousTick = curTick();
7703184Srdreslin@umich.edu
7715728Sgblack@eecs.umich.edu    if (pkt->senderState) {
7725728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
7735728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
7745728Sgblack@eecs.umich.edu        assert(send_state);
7755728Sgblack@eecs.umich.edu        delete pkt->req;
7765728Sgblack@eecs.umich.edu        delete pkt;
7775728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
7785728Sgblack@eecs.umich.edu        delete send_state;
7795728Sgblack@eecs.umich.edu
7805728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
7815728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
7825728Sgblack@eecs.umich.edu        assert(main_send_state);
7835728Sgblack@eecs.umich.edu        // Record the fact that this packet is no longer outstanding.
7845728Sgblack@eecs.umich.edu        assert(main_send_state->outstanding != 0);
7855728Sgblack@eecs.umich.edu        main_send_state->outstanding--;
7865728Sgblack@eecs.umich.edu
7875728Sgblack@eecs.umich.edu        if (main_send_state->outstanding) {
7885728Sgblack@eecs.umich.edu            return;
7895728Sgblack@eecs.umich.edu        } else {
7905728Sgblack@eecs.umich.edu            delete main_send_state;
7915728Sgblack@eecs.umich.edu            big_pkt->senderState = NULL;
7925728Sgblack@eecs.umich.edu            pkt = big_pkt;
7935728Sgblack@eecs.umich.edu        }
7945728Sgblack@eecs.umich.edu    }
7955728Sgblack@eecs.umich.edu
7965728Sgblack@eecs.umich.edu    _status = Running;
7975728Sgblack@eecs.umich.edu
7982623SN/A    Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
7992623SN/A
8004998Sgblack@eecs.umich.edu    // keep an instruction count
8014998Sgblack@eecs.umich.edu    if (fault == NoFault)
8024998Sgblack@eecs.umich.edu        countInst();
8035001Sgblack@eecs.umich.edu    else if (traceData) {
8045001Sgblack@eecs.umich.edu        // If there was a fault, we shouldn't trace this instruction.
8055001Sgblack@eecs.umich.edu        delete traceData;
8065001Sgblack@eecs.umich.edu        traceData = NULL;
8075001Sgblack@eecs.umich.edu    }
8084998Sgblack@eecs.umich.edu
8095507Sstever@gmail.com    // the locked flag may be cleared on the response packet, so check
8105507Sstever@gmail.com    // pkt->req and not pkt to see if it was a load-locked
8116102Sgblack@eecs.umich.edu    if (pkt->isRead() && pkt->req->isLLSC()) {
8123170Sstever@eecs.umich.edu        TheISA::handleLockedRead(thread, pkt->req);
8133170Sstever@eecs.umich.edu    }
8143170Sstever@eecs.umich.edu
8152644Sstever@eecs.umich.edu    delete pkt->req;
8162644Sstever@eecs.umich.edu    delete pkt;
8172644Sstever@eecs.umich.edu
8183184Srdreslin@umich.edu    postExecute();
8193227Sktlim@umich.edu
8203201Shsul@eecs.umich.edu    if (getState() == SimObject::Draining) {
8213201Shsul@eecs.umich.edu        advancePC(fault);
8223201Shsul@eecs.umich.edu        completeDrain();
8233201Shsul@eecs.umich.edu
8243201Shsul@eecs.umich.edu        return;
8253201Shsul@eecs.umich.edu    }
8263201Shsul@eecs.umich.edu
8272644Sstever@eecs.umich.edu    advanceInst(fault);
8282623SN/A}
8292623SN/A
8302623SN/A
8312798Sktlim@umich.eduvoid
8322839Sktlim@umich.eduTimingSimpleCPU::completeDrain()
8332798Sktlim@umich.edu{
8342839Sktlim@umich.edu    DPRINTF(Config, "Done draining\n");
8352901Ssaidi@eecs.umich.edu    changeState(SimObject::Drained);
8362839Sktlim@umich.edu    drainEvent->process();
8372798Sktlim@umich.edu}
8382623SN/A
8392623SN/Abool
8403349Sbinkertn@umich.eduTimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt)
8412623SN/A{
8428948Sandreas.hansson@arm.com    assert(pkt->isResponse());
8438948Sandreas.hansson@arm.com    if (!pkt->wasNacked()) {
8443310Srdreslin@umich.edu        // delay processing of returned data until next CPU clock edge
8457823Ssteve.reinhardt@amd.com        Tick next_tick = cpu->nextCycle(curTick());
8462948Ssaidi@eecs.umich.edu
8477823Ssteve.reinhardt@amd.com        if (next_tick == curTick()) {
8483310Srdreslin@umich.edu            cpu->completeDataAccess(pkt);
8495728Sgblack@eecs.umich.edu        } else {
8507745SAli.Saidi@ARM.com            if (!tickEvent.scheduled()) {
8517745SAli.Saidi@ARM.com                tickEvent.schedule(pkt, next_tick);
8527745SAli.Saidi@ARM.com            } else {
8537745SAli.Saidi@ARM.com                // In the case of a split transaction and a cache that is
8547745SAli.Saidi@ARM.com                // faster than a CPU we could get two responses before
8557745SAli.Saidi@ARM.com                // next_tick expires
8567745SAli.Saidi@ARM.com                if (!retryEvent.scheduled())
8578708Sandreas.hansson@arm.com                    cpu->schedule(retryEvent, next_tick);
8587745SAli.Saidi@ARM.com                return false;
8597745SAli.Saidi@ARM.com            }
8605728Sgblack@eecs.umich.edu        }
8612948Ssaidi@eecs.umich.edu
8623310Srdreslin@umich.edu        return true;
8638948Sandreas.hansson@arm.com    } else  {
8644433Ssaidi@eecs.umich.edu        assert(cpu->_status == DcacheWaitResponse);
8654433Ssaidi@eecs.umich.edu        pkt->reinitNacked();
8664433Ssaidi@eecs.umich.edu        if (!sendTiming(pkt)) {
8674433Ssaidi@eecs.umich.edu            cpu->_status = DcacheRetry;
8684433Ssaidi@eecs.umich.edu            cpu->dcache_pkt = pkt;
8694433Ssaidi@eecs.umich.edu        }
8703310Srdreslin@umich.edu    }
8718948Sandreas.hansson@arm.com
8724433Ssaidi@eecs.umich.edu    return true;
8732948Ssaidi@eecs.umich.edu}
8742948Ssaidi@eecs.umich.edu
8752948Ssaidi@eecs.umich.eduvoid
8762948Ssaidi@eecs.umich.eduTimingSimpleCPU::DcachePort::DTickEvent::process()
8772948Ssaidi@eecs.umich.edu{
8782630SN/A    cpu->completeDataAccess(pkt);
8792623SN/A}
8802623SN/A
8812657Ssaidi@eecs.umich.eduvoid
8822623SN/ATimingSimpleCPU::DcachePort::recvRetry()
8832623SN/A{
8842623SN/A    // we shouldn't get a retry unless we have a packet that we're
8852623SN/A    // waiting to transmit
8862623SN/A    assert(cpu->dcache_pkt != NULL);
8872623SN/A    assert(cpu->_status == DcacheRetry);
8883349Sbinkertn@umich.edu    PacketPtr tmp = cpu->dcache_pkt;
8895728Sgblack@eecs.umich.edu    if (tmp->senderState) {
8905728Sgblack@eecs.umich.edu        // This is a packet from a split access.
8915728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
8925728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(tmp->senderState);
8935728Sgblack@eecs.umich.edu        assert(send_state);
8945728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
8955728Sgblack@eecs.umich.edu
8965728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
8975728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
8985728Sgblack@eecs.umich.edu        assert(main_send_state);
8995728Sgblack@eecs.umich.edu
9005728Sgblack@eecs.umich.edu        if (sendTiming(tmp)) {
9015728Sgblack@eecs.umich.edu            // If we were able to send without retrying, record that fact
9025728Sgblack@eecs.umich.edu            // and try sending the other fragment.
9035728Sgblack@eecs.umich.edu            send_state->clearFromParent();
9045728Sgblack@eecs.umich.edu            int other_index = main_send_state->getPendingFragment();
9055728Sgblack@eecs.umich.edu            if (other_index > 0) {
9065728Sgblack@eecs.umich.edu                tmp = main_send_state->fragments[other_index];
9075728Sgblack@eecs.umich.edu                cpu->dcache_pkt = tmp;
9085728Sgblack@eecs.umich.edu                if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) ||
9095728Sgblack@eecs.umich.edu                        (big_pkt->isWrite() && cpu->handleWritePacket())) {
9105728Sgblack@eecs.umich.edu                    main_send_state->fragments[other_index] = NULL;
9115728Sgblack@eecs.umich.edu                }
9125728Sgblack@eecs.umich.edu            } else {
9135728Sgblack@eecs.umich.edu                cpu->_status = DcacheWaitResponse;
9145728Sgblack@eecs.umich.edu                // memory system takes ownership of packet
9155728Sgblack@eecs.umich.edu                cpu->dcache_pkt = NULL;
9165728Sgblack@eecs.umich.edu            }
9175728Sgblack@eecs.umich.edu        }
9185728Sgblack@eecs.umich.edu    } else if (sendTiming(tmp)) {
9192657Ssaidi@eecs.umich.edu        cpu->_status = DcacheWaitResponse;
9203170Sstever@eecs.umich.edu        // memory system takes ownership of packet
9212657Ssaidi@eecs.umich.edu        cpu->dcache_pkt = NULL;
9222657Ssaidi@eecs.umich.edu    }
9232623SN/A}
9242623SN/A
9255606Snate@binkert.orgTimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu,
9265606Snate@binkert.org    Tick t)
9275606Snate@binkert.org    : pkt(_pkt), cpu(_cpu)
9285103Ssaidi@eecs.umich.edu{
9295606Snate@binkert.org    cpu->schedule(this, t);
9305103Ssaidi@eecs.umich.edu}
9315103Ssaidi@eecs.umich.edu
9325103Ssaidi@eecs.umich.eduvoid
9335103Ssaidi@eecs.umich.eduTimingSimpleCPU::IprEvent::process()
9345103Ssaidi@eecs.umich.edu{
9355103Ssaidi@eecs.umich.edu    cpu->completeDataAccess(pkt);
9365103Ssaidi@eecs.umich.edu}
9375103Ssaidi@eecs.umich.edu
9385103Ssaidi@eecs.umich.educonst char *
9395336Shines@cs.fsu.eduTimingSimpleCPU::IprEvent::description() const
9405103Ssaidi@eecs.umich.edu{
9415103Ssaidi@eecs.umich.edu    return "Timing Simple CPU Delay IPR event";
9425103Ssaidi@eecs.umich.edu}
9435103Ssaidi@eecs.umich.edu
9442623SN/A
9455315Sstever@gmail.comvoid
9465315Sstever@gmail.comTimingSimpleCPU::printAddr(Addr a)
9475315Sstever@gmail.com{
9485315Sstever@gmail.com    dcachePort.printAddr(a);
9495315Sstever@gmail.com}
9505315Sstever@gmail.com
9515315Sstever@gmail.com
9522623SN/A////////////////////////////////////////////////////////////////////////
9532623SN/A//
9542623SN/A//  TimingSimpleCPU Simulation Object
9552623SN/A//
9564762Snate@binkert.orgTimingSimpleCPU *
9574762Snate@binkert.orgTimingSimpleCPUParams::create()
9582623SN/A{
9595529Snate@binkert.org    numThreads = 1;
9608779Sgblack@eecs.umich.edu    if (!FullSystem && workload.size() != 1)
9614762Snate@binkert.org        panic("only one workload allowed");
9625529Snate@binkert.org    return new TimingSimpleCPU(this);
9632623SN/A}
964