timing.cc revision 9180
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"
519152Satgutier@umich.edu#include "debug/Drain.hh"
528232Snate@binkert.org#include "debug/ExecFaulting.hh"
538232Snate@binkert.org#include "debug/SimpleCPU.hh"
543348Sbinkertn@umich.edu#include "mem/packet.hh"
553348Sbinkertn@umich.edu#include "mem/packet_access.hh"
564762Snate@binkert.org#include "params/TimingSimpleCPU.hh"
577678Sgblack@eecs.umich.edu#include "sim/faults.hh"
588779Sgblack@eecs.umich.edu#include "sim/full_system.hh"
592901Ssaidi@eecs.umich.edu#include "sim/system.hh"
602623SN/A
612623SN/Ausing namespace std;
622623SN/Ausing namespace TheISA;
632623SN/A
642623SN/Avoid
652623SN/ATimingSimpleCPU::init()
662623SN/A{
672623SN/A    BaseCPU::init();
688921Sandreas.hansson@arm.com
698921Sandreas.hansson@arm.com    // Initialise the ThreadContext's memory proxies
708921Sandreas.hansson@arm.com    tcBase()->initMemProxies(tcBase());
718921Sandreas.hansson@arm.com
729058Satgutier@umich.edu    if (FullSystem && !params()->defer_registration) {
738779Sgblack@eecs.umich.edu        for (int i = 0; i < threadContexts.size(); ++i) {
748779Sgblack@eecs.umich.edu            ThreadContext *tc = threadContexts[i];
758779Sgblack@eecs.umich.edu            // initialize CPU, including PC
768779Sgblack@eecs.umich.edu            TheISA::initCPU(tc, _cpuId);
778779Sgblack@eecs.umich.edu        }
782623SN/A    }
792623SN/A}
802623SN/A
812623SN/Avoid
828707Sandreas.hansson@arm.comTimingSimpleCPU::TimingCPUPort::TickEvent::schedule(PacketPtr _pkt, Tick t)
832948Ssaidi@eecs.umich.edu{
842948Ssaidi@eecs.umich.edu    pkt = _pkt;
855606Snate@binkert.org    cpu->schedule(this, t);
862948Ssaidi@eecs.umich.edu}
872948Ssaidi@eecs.umich.edu
885529Snate@binkert.orgTimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p)
898707Sandreas.hansson@arm.com    : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this),
909179Sandreas.hansson@arm.com      dcachePort(this), ifetch_pkt(NULL), dcache_pkt(NULL), previousCycle(0),
919179Sandreas.hansson@arm.com      fetchEvent(this)
922623SN/A{
932623SN/A    _status = Idle;
943647Srdreslin@umich.edu
952901Ssaidi@eecs.umich.edu    changeState(SimObject::Running);
967897Shestness@cs.utexas.edu    system->totalNumInsts = 0;
972623SN/A}
982623SN/A
992623SN/A
1002623SN/ATimingSimpleCPU::~TimingSimpleCPU()
1012623SN/A{
1022623SN/A}
1032623SN/A
1042623SN/Avoid
1052623SN/ATimingSimpleCPU::serialize(ostream &os)
1062623SN/A{
1072915Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
1082915Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
1092623SN/A    BaseSimpleCPU::serialize(os);
1102623SN/A}
1112623SN/A
1122623SN/Avoid
1132623SN/ATimingSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1142623SN/A{
1152915Sktlim@umich.edu    SimObject::State so_state;
1162915Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
1172623SN/A    BaseSimpleCPU::unserialize(cp, section);
1182798Sktlim@umich.edu}
1192798Sktlim@umich.edu
1202901Ssaidi@eecs.umich.eduunsigned int
1212839Sktlim@umich.eduTimingSimpleCPU::drain(Event *drain_event)
1222798Sktlim@umich.edu{
1232839Sktlim@umich.edu    // TimingSimpleCPU is ready to drain if it's not waiting for
1242798Sktlim@umich.edu    // an access to complete.
1255496Ssaidi@eecs.umich.edu    if (_status == Idle || _status == Running || _status == SwitchedOut) {
1262901Ssaidi@eecs.umich.edu        changeState(SimObject::Drained);
1272901Ssaidi@eecs.umich.edu        return 0;
1282798Sktlim@umich.edu    } else {
1292839Sktlim@umich.edu        changeState(SimObject::Draining);
1302839Sktlim@umich.edu        drainEvent = drain_event;
1319152Satgutier@umich.edu        DPRINTF(Drain, "CPU not drained\n");
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;
1579179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
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);
1859179Sandreas.hansson@arm.com    previousCycle = curCycle();
1862623SN/A}
1872623SN/A
1882623SN/A
1892623SN/Avoid
1909180Sandreas.hansson@arm.comTimingSimpleCPU::activateContext(ThreadID thread_num, Cycles 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
2039179Sandreas.hansson@arm.com    schedule(fetchEvent, clockEdge(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()) {
2329180Sandreas.hansson@arm.com        Cycles delay = TheISA::handleIprRead(thread->getTC(), pkt);
2339179Sandreas.hansson@arm.com        new IprEvent(pkt, this, clockEdge(delay));
2345728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2355728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2368975Sandreas.hansson@arm.com    } else if (!dcachePort.sendTimingReq(pkt)) {
2375728Sgblack@eecs.umich.edu        _status = DcacheRetry;
2385728Sgblack@eecs.umich.edu        dcache_pkt = pkt;
2395728Sgblack@eecs.umich.edu    } else {
2405728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2415728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
2425728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2435728Sgblack@eecs.umich.edu    }
2445728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
2455728Sgblack@eecs.umich.edu}
2462623SN/A
2475894Sgblack@eecs.umich.eduvoid
2486973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
2496973Stjones1@inf.ed.ac.uk                          bool read)
2505744Sgblack@eecs.umich.edu{
2515894Sgblack@eecs.umich.edu    PacketPtr pkt;
2525894Sgblack@eecs.umich.edu    buildPacket(pkt, req, read);
2537691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
2545894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2555894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2565894Sgblack@eecs.umich.edu        pkt->makeResponse();
2575894Sgblack@eecs.umich.edu        completeDataAccess(pkt);
2585894Sgblack@eecs.umich.edu    } else if (read) {
2595894Sgblack@eecs.umich.edu        handleReadPacket(pkt);
2605894Sgblack@eecs.umich.edu    } else {
2615894Sgblack@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
2625894Sgblack@eecs.umich.edu
2636102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
2645894Sgblack@eecs.umich.edu            do_access = TheISA::handleLockedWrite(thread, req);
2655894Sgblack@eecs.umich.edu        } else if (req->isCondSwap()) {
2665894Sgblack@eecs.umich.edu            assert(res);
2675894Sgblack@eecs.umich.edu            req->setExtraData(*res);
2685894Sgblack@eecs.umich.edu        }
2695894Sgblack@eecs.umich.edu
2705894Sgblack@eecs.umich.edu        if (do_access) {
2715894Sgblack@eecs.umich.edu            dcache_pkt = pkt;
2725894Sgblack@eecs.umich.edu            handleWritePacket();
2735894Sgblack@eecs.umich.edu        } else {
2745894Sgblack@eecs.umich.edu            _status = DcacheWaitResponse;
2755894Sgblack@eecs.umich.edu            completeDataAccess(pkt);
2765894Sgblack@eecs.umich.edu        }
2775894Sgblack@eecs.umich.edu    }
2785894Sgblack@eecs.umich.edu}
2795894Sgblack@eecs.umich.edu
2805894Sgblack@eecs.umich.eduvoid
2816973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendSplitData(RequestPtr req1, RequestPtr req2,
2826973Stjones1@inf.ed.ac.uk                               RequestPtr req, uint8_t *data, bool read)
2835894Sgblack@eecs.umich.edu{
2845894Sgblack@eecs.umich.edu    PacketPtr pkt1, pkt2;
2855894Sgblack@eecs.umich.edu    buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
2865894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2875894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2885894Sgblack@eecs.umich.edu        pkt1->makeResponse();
2895894Sgblack@eecs.umich.edu        completeDataAccess(pkt1);
2905894Sgblack@eecs.umich.edu    } else if (read) {
2917911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
2927911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
2935894Sgblack@eecs.umich.edu        if (handleReadPacket(pkt1)) {
2945894Sgblack@eecs.umich.edu            send_state->clearFromParent();
2957911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
2967911Shestness@cs.utexas.edu                    pkt2->senderState);
2975894Sgblack@eecs.umich.edu            if (handleReadPacket(pkt2)) {
2985894Sgblack@eecs.umich.edu                send_state->clearFromParent();
2995894Sgblack@eecs.umich.edu            }
3005894Sgblack@eecs.umich.edu        }
3015894Sgblack@eecs.umich.edu    } else {
3025894Sgblack@eecs.umich.edu        dcache_pkt = pkt1;
3037911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
3047911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3055894Sgblack@eecs.umich.edu        if (handleWritePacket()) {
3065894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3075894Sgblack@eecs.umich.edu            dcache_pkt = pkt2;
3087911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
3097911Shestness@cs.utexas.edu                    pkt2->senderState);
3105894Sgblack@eecs.umich.edu            if (handleWritePacket()) {
3115894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3125894Sgblack@eecs.umich.edu            }
3135894Sgblack@eecs.umich.edu        }
3145894Sgblack@eecs.umich.edu    }
3155894Sgblack@eecs.umich.edu}
3165894Sgblack@eecs.umich.edu
3175894Sgblack@eecs.umich.eduvoid
3185894Sgblack@eecs.umich.eduTimingSimpleCPU::translationFault(Fault fault)
3195894Sgblack@eecs.umich.edu{
3206739Sgblack@eecs.umich.edu    // fault may be NoFault in cases where a fault is suppressed,
3216739Sgblack@eecs.umich.edu    // for instance prefetches.
3229179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
3239179Sandreas.hansson@arm.com    previousCycle = curCycle();
3245894Sgblack@eecs.umich.edu
3255894Sgblack@eecs.umich.edu    if (traceData) {
3265894Sgblack@eecs.umich.edu        // Since there was a fault, we shouldn't trace this instruction.
3275894Sgblack@eecs.umich.edu        delete traceData;
3285894Sgblack@eecs.umich.edu        traceData = NULL;
3295744Sgblack@eecs.umich.edu    }
3305744Sgblack@eecs.umich.edu
3315894Sgblack@eecs.umich.edu    postExecute();
3325894Sgblack@eecs.umich.edu
3335894Sgblack@eecs.umich.edu    if (getState() == SimObject::Draining) {
3345894Sgblack@eecs.umich.edu        advancePC(fault);
3355894Sgblack@eecs.umich.edu        completeDrain();
3365894Sgblack@eecs.umich.edu    } else {
3375894Sgblack@eecs.umich.edu        advanceInst(fault);
3385894Sgblack@eecs.umich.edu    }
3395894Sgblack@eecs.umich.edu}
3405894Sgblack@eecs.umich.edu
3415894Sgblack@eecs.umich.eduvoid
3425894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
3435894Sgblack@eecs.umich.edu{
3445894Sgblack@eecs.umich.edu    MemCmd cmd;
3455894Sgblack@eecs.umich.edu    if (read) {
3465894Sgblack@eecs.umich.edu        cmd = MemCmd::ReadReq;
3476102Sgblack@eecs.umich.edu        if (req->isLLSC())
3485894Sgblack@eecs.umich.edu            cmd = MemCmd::LoadLockedReq;
3495894Sgblack@eecs.umich.edu    } else {
3505894Sgblack@eecs.umich.edu        cmd = MemCmd::WriteReq;
3516102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
3525894Sgblack@eecs.umich.edu            cmd = MemCmd::StoreCondReq;
3535894Sgblack@eecs.umich.edu        } else if (req->isSwap()) {
3545894Sgblack@eecs.umich.edu            cmd = MemCmd::SwapReq;
3555894Sgblack@eecs.umich.edu        }
3565894Sgblack@eecs.umich.edu    }
3578949Sandreas.hansson@arm.com    pkt = new Packet(req, cmd);
3585894Sgblack@eecs.umich.edu}
3595894Sgblack@eecs.umich.edu
3605894Sgblack@eecs.umich.eduvoid
3615894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
3625894Sgblack@eecs.umich.edu        RequestPtr req1, RequestPtr req2, RequestPtr req,
3635894Sgblack@eecs.umich.edu        uint8_t *data, bool read)
3645894Sgblack@eecs.umich.edu{
3655894Sgblack@eecs.umich.edu    pkt1 = pkt2 = NULL;
3665894Sgblack@eecs.umich.edu
3678105Sgblack@eecs.umich.edu    assert(!req1->isMmappedIpr() && !req2->isMmappedIpr());
3685744Sgblack@eecs.umich.edu
3695894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3705894Sgblack@eecs.umich.edu        buildPacket(pkt1, req, read);
3715894Sgblack@eecs.umich.edu        return;
3725894Sgblack@eecs.umich.edu    }
3735894Sgblack@eecs.umich.edu
3745894Sgblack@eecs.umich.edu    buildPacket(pkt1, req1, read);
3755894Sgblack@eecs.umich.edu    buildPacket(pkt2, req2, read);
3765894Sgblack@eecs.umich.edu
3778832SAli.Saidi@ARM.com    req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags(), dataMasterId());
3788949Sandreas.hansson@arm.com    PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand());
3795744Sgblack@eecs.umich.edu
3807691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
3815744Sgblack@eecs.umich.edu    pkt1->dataStatic<uint8_t>(data);
3825744Sgblack@eecs.umich.edu    pkt2->dataStatic<uint8_t>(data + req1->getSize());
3835744Sgblack@eecs.umich.edu
3845744Sgblack@eecs.umich.edu    SplitMainSenderState * main_send_state = new SplitMainSenderState;
3855744Sgblack@eecs.umich.edu    pkt->senderState = main_send_state;
3865744Sgblack@eecs.umich.edu    main_send_state->fragments[0] = pkt1;
3875744Sgblack@eecs.umich.edu    main_send_state->fragments[1] = pkt2;
3885744Sgblack@eecs.umich.edu    main_send_state->outstanding = 2;
3895744Sgblack@eecs.umich.edu    pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
3905744Sgblack@eecs.umich.edu    pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
3915744Sgblack@eecs.umich.edu}
3925744Sgblack@eecs.umich.edu
3932623SN/AFault
3948444Sgblack@eecs.umich.eduTimingSimpleCPU::readMem(Addr addr, uint8_t *data,
3958444Sgblack@eecs.umich.edu                         unsigned size, unsigned flags)
3962623SN/A{
3975728Sgblack@eecs.umich.edu    Fault fault;
3985728Sgblack@eecs.umich.edu    const int asid = 0;
3996221Snate@binkert.org    const ThreadID tid = 0;
4007720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4016227Snate@binkert.org    unsigned block_size = dcachePort.peerBlockSize();
4026973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Read;
4032623SN/A
4047045Ssteve.reinhardt@amd.com    if (traceData) {
4057045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4067045Ssteve.reinhardt@amd.com    }
4077045Ssteve.reinhardt@amd.com
4087520Sgblack@eecs.umich.edu    RequestPtr req  = new Request(asid, addr, size,
4098832SAli.Saidi@ARM.com                                  flags, dataMasterId(), pc, _cpuId, tid);
4105728Sgblack@eecs.umich.edu
4117520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4125744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4135728Sgblack@eecs.umich.edu
4145894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4155744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4165894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4176102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4185894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4195894Sgblack@eecs.umich.edu
4206973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4217520Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, new uint8_t[size],
4226973Stjones1@inf.ed.ac.uk                                      NULL, mode);
4238486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4248486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4258486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
4268486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
4276973Stjones1@inf.ed.ac.uk
4286973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
4296973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
4305744Sgblack@eecs.umich.edu    } else {
4316973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4327520Sgblack@eecs.umich.edu            new WholeTranslationState(req, new uint8_t[size], NULL, mode);
4338486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation
4348486Sgblack@eecs.umich.edu            = new DataTranslation<TimingSimpleCPU *>(this, state);
4356973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
4362623SN/A    }
4372623SN/A
4385728Sgblack@eecs.umich.edu    return NoFault;
4392623SN/A}
4402623SN/A
4415728Sgblack@eecs.umich.edubool
4425728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket()
4435728Sgblack@eecs.umich.edu{
4445728Sgblack@eecs.umich.edu    RequestPtr req = dcache_pkt->req;
4458105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
4469180Sandreas.hansson@arm.com        Cycles delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
4479179Sandreas.hansson@arm.com        new IprEvent(dcache_pkt, this, clockEdge(delay));
4485728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4495728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4508975Sandreas.hansson@arm.com    } else if (!dcachePort.sendTimingReq(dcache_pkt)) {
4515728Sgblack@eecs.umich.edu        _status = DcacheRetry;
4525728Sgblack@eecs.umich.edu    } else {
4535728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4545728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
4555728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4565728Sgblack@eecs.umich.edu    }
4575728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
4585728Sgblack@eecs.umich.edu}
4592623SN/A
4602623SN/AFault
4618444Sgblack@eecs.umich.eduTimingSimpleCPU::writeMem(uint8_t *data, unsigned size,
4628444Sgblack@eecs.umich.edu                          Addr addr, unsigned flags, uint64_t *res)
4632623SN/A{
4648443Sgblack@eecs.umich.edu    uint8_t *newData = new uint8_t[size];
4658443Sgblack@eecs.umich.edu    memcpy(newData, data, size);
4668443Sgblack@eecs.umich.edu
4675728Sgblack@eecs.umich.edu    const int asid = 0;
4686221Snate@binkert.org    const ThreadID tid = 0;
4697720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4706227Snate@binkert.org    unsigned block_size = dcachePort.peerBlockSize();
4716973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Write;
4723169Sstever@eecs.umich.edu
4737045Ssteve.reinhardt@amd.com    if (traceData) {
4747045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4757045Ssteve.reinhardt@amd.com    }
4767045Ssteve.reinhardt@amd.com
4777520Sgblack@eecs.umich.edu    RequestPtr req = new Request(asid, addr, size,
4788832SAli.Saidi@ARM.com                                 flags, dataMasterId(), pc, _cpuId, tid);
4795728Sgblack@eecs.umich.edu
4807520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4815744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4825728Sgblack@eecs.umich.edu
4835894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4845744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4855894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4866102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4875894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4885894Sgblack@eecs.umich.edu
4896973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4908443Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, newData, res, mode);
4918486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4928486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4938486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
4948486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
4956973Stjones1@inf.ed.ac.uk
4966973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
4976973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
4985744Sgblack@eecs.umich.edu    } else {
4996973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
5008443Sgblack@eecs.umich.edu            new WholeTranslationState(req, newData, res, mode);
5018486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation =
5028486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state);
5036973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
5042623SN/A    }
5052623SN/A
5067045Ssteve.reinhardt@amd.com    // Translation faults will be returned via finishTranslation()
5075728Sgblack@eecs.umich.edu    return NoFault;
5082623SN/A}
5092623SN/A
5102623SN/A
5112623SN/Avoid
5126973Stjones1@inf.ed.ac.ukTimingSimpleCPU::finishTranslation(WholeTranslationState *state)
5136973Stjones1@inf.ed.ac.uk{
5146973Stjones1@inf.ed.ac.uk    _status = Running;
5156973Stjones1@inf.ed.ac.uk
5166973Stjones1@inf.ed.ac.uk    if (state->getFault() != NoFault) {
5176973Stjones1@inf.ed.ac.uk        if (state->isPrefetch()) {
5186973Stjones1@inf.ed.ac.uk            state->setNoFault();
5196973Stjones1@inf.ed.ac.uk        }
5207691SAli.Saidi@ARM.com        delete [] state->data;
5216973Stjones1@inf.ed.ac.uk        state->deleteReqs();
5226973Stjones1@inf.ed.ac.uk        translationFault(state->getFault());
5236973Stjones1@inf.ed.ac.uk    } else {
5246973Stjones1@inf.ed.ac.uk        if (!state->isSplit) {
5256973Stjones1@inf.ed.ac.uk            sendData(state->mainReq, state->data, state->res,
5266973Stjones1@inf.ed.ac.uk                     state->mode == BaseTLB::Read);
5276973Stjones1@inf.ed.ac.uk        } else {
5286973Stjones1@inf.ed.ac.uk            sendSplitData(state->sreqLow, state->sreqHigh, state->mainReq,
5296973Stjones1@inf.ed.ac.uk                          state->data, state->mode == BaseTLB::Read);
5306973Stjones1@inf.ed.ac.uk        }
5316973Stjones1@inf.ed.ac.uk    }
5326973Stjones1@inf.ed.ac.uk
5336973Stjones1@inf.ed.ac.uk    delete state;
5346973Stjones1@inf.ed.ac.uk}
5356973Stjones1@inf.ed.ac.uk
5366973Stjones1@inf.ed.ac.uk
5376973Stjones1@inf.ed.ac.ukvoid
5382623SN/ATimingSimpleCPU::fetch()
5392623SN/A{
5405221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Fetch\n");
5415221Ssaidi@eecs.umich.edu
5423387Sgblack@eecs.umich.edu    if (!curStaticInst || !curStaticInst->isDelayedCommit())
5433387Sgblack@eecs.umich.edu        checkForInterrupts();
5442631SN/A
5455348Ssaidi@eecs.umich.edu    checkPcEventQueue();
5465348Ssaidi@eecs.umich.edu
5478143SAli.Saidi@ARM.com    // We must have just got suspended by a PC event
5488143SAli.Saidi@ARM.com    if (_status == Idle)
5498143SAli.Saidi@ARM.com        return;
5508143SAli.Saidi@ARM.com
5517720Sgblack@eecs.umich.edu    TheISA::PCState pcState = thread->pcState();
5527720Sgblack@eecs.umich.edu    bool needToFetch = !isRomMicroPC(pcState.microPC()) && !curMacroStaticInst;
5532623SN/A
5547720Sgblack@eecs.umich.edu    if (needToFetch) {
5558276SAli.Saidi@ARM.com        _status = Running;
5565669Sgblack@eecs.umich.edu        Request *ifetch_req = new Request();
5575712Shsul@eecs.umich.edu        ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0);
5585894Sgblack@eecs.umich.edu        setupFetchRequest(ifetch_req);
5598277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translating address %#x\n", ifetch_req->getVaddr());
5606023Snate@binkert.org        thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation,
5616023Snate@binkert.org                BaseTLB::Execute);
5622623SN/A    } else {
5635669Sgblack@eecs.umich.edu        _status = IcacheWaitResponse;
5645669Sgblack@eecs.umich.edu        completeIfetch(NULL);
5655894Sgblack@eecs.umich.edu
5669179Sandreas.hansson@arm.com        numCycles += curCycle() - previousCycle;
5679179Sandreas.hansson@arm.com        previousCycle = curCycle();
5685894Sgblack@eecs.umich.edu    }
5695894Sgblack@eecs.umich.edu}
5705894Sgblack@eecs.umich.edu
5715894Sgblack@eecs.umich.edu
5725894Sgblack@eecs.umich.eduvoid
5735894Sgblack@eecs.umich.eduTimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc)
5745894Sgblack@eecs.umich.edu{
5755894Sgblack@eecs.umich.edu    if (fault == NoFault) {
5768277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Sending fetch for addr %#x(pa: %#x)\n",
5778277SAli.Saidi@ARM.com                req->getVaddr(), req->getPaddr());
5788949Sandreas.hansson@arm.com        ifetch_pkt = new Packet(req, MemCmd::ReadReq);
5795894Sgblack@eecs.umich.edu        ifetch_pkt->dataStatic(&inst);
5808277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, " -- pkt addr: %#x\n", ifetch_pkt->getAddr());
5815894Sgblack@eecs.umich.edu
5828975Sandreas.hansson@arm.com        if (!icachePort.sendTimingReq(ifetch_pkt)) {
5835894Sgblack@eecs.umich.edu            // Need to wait for retry
5845894Sgblack@eecs.umich.edu            _status = IcacheRetry;
5855894Sgblack@eecs.umich.edu        } else {
5865894Sgblack@eecs.umich.edu            // Need to wait for cache to respond
5875894Sgblack@eecs.umich.edu            _status = IcacheWaitResponse;
5885894Sgblack@eecs.umich.edu            // ownership of packet transferred to memory system
5895894Sgblack@eecs.umich.edu            ifetch_pkt = NULL;
5905894Sgblack@eecs.umich.edu        }
5915894Sgblack@eecs.umich.edu    } else {
5928277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translation of addr %#x faulted\n", req->getVaddr());
5935894Sgblack@eecs.umich.edu        delete req;
5945894Sgblack@eecs.umich.edu        // fetch fault: advance directly to next instruction (fault handler)
5957945SAli.Saidi@ARM.com        _status = Running;
5965894Sgblack@eecs.umich.edu        advanceInst(fault);
5972623SN/A    }
5983222Sktlim@umich.edu
5999179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
6009179Sandreas.hansson@arm.com    previousCycle = curCycle();
6012623SN/A}
6022623SN/A
6032623SN/A
6042623SN/Avoid
6052644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault)
6062623SN/A{
6078276SAli.Saidi@ARM.com
6088276SAli.Saidi@ARM.com    if (_status == Faulting)
6098276SAli.Saidi@ARM.com        return;
6108276SAli.Saidi@ARM.com
6118276SAli.Saidi@ARM.com    if (fault != NoFault) {
6128276SAli.Saidi@ARM.com        advancePC(fault);
6138276SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Fault occured, scheduling fetch event\n");
6148276SAli.Saidi@ARM.com        reschedule(fetchEvent, nextCycle(), true);
6158276SAli.Saidi@ARM.com        _status = Faulting;
6168276SAli.Saidi@ARM.com        return;
6178276SAli.Saidi@ARM.com    }
6188276SAli.Saidi@ARM.com
6198276SAli.Saidi@ARM.com
6208276SAli.Saidi@ARM.com    if (!stayAtPC)
6215726Sgblack@eecs.umich.edu        advancePC(fault);
6222623SN/A
6232631SN/A    if (_status == Running) {
6242631SN/A        // kick off fetch of next instruction... callback from icache
6252631SN/A        // response will cause that instruction to be executed,
6262631SN/A        // keeping the CPU running.
6272631SN/A        fetch();
6282631SN/A    }
6292623SN/A}
6302623SN/A
6312623SN/A
6322623SN/Avoid
6333349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt)
6342623SN/A{
6358277SAli.Saidi@ARM.com    DPRINTF(SimpleCPU, "Complete ICache Fetch for addr %#x\n", pkt ?
6368277SAli.Saidi@ARM.com            pkt->getAddr() : 0);
6378277SAli.Saidi@ARM.com
6382623SN/A    // received a response from the icache: execute the received
6392623SN/A    // instruction
6405669Sgblack@eecs.umich.edu
6415669Sgblack@eecs.umich.edu    assert(!pkt || !pkt->isError());
6422623SN/A    assert(_status == IcacheWaitResponse);
6432798Sktlim@umich.edu
6442623SN/A    _status = Running;
6452644Sstever@eecs.umich.edu
6469179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
6479179Sandreas.hansson@arm.com    previousCycle = curCycle();
6483222Sktlim@umich.edu
6492839Sktlim@umich.edu    if (getState() == SimObject::Draining) {
6505669Sgblack@eecs.umich.edu        if (pkt) {
6515669Sgblack@eecs.umich.edu            delete pkt->req;
6525669Sgblack@eecs.umich.edu            delete pkt;
6535669Sgblack@eecs.umich.edu        }
6543658Sktlim@umich.edu
6552839Sktlim@umich.edu        completeDrain();
6562798Sktlim@umich.edu        return;
6572798Sktlim@umich.edu    }
6582798Sktlim@umich.edu
6592623SN/A    preExecute();
6607725SAli.Saidi@ARM.com    if (curStaticInst && curStaticInst->isMemRef()) {
6612623SN/A        // load or store: just send to dcache
6622623SN/A        Fault fault = curStaticInst->initiateAcc(this, traceData);
6637945SAli.Saidi@ARM.com
6647945SAli.Saidi@ARM.com        // If we're not running now the instruction will complete in a dcache
6657945SAli.Saidi@ARM.com        // response callback or the instruction faulted and has started an
6667945SAli.Saidi@ARM.com        // ifetch
6677945SAli.Saidi@ARM.com        if (_status == Running) {
6685894Sgblack@eecs.umich.edu            if (fault != NoFault && traceData) {
6695001Sgblack@eecs.umich.edu                // If there was a fault, we shouldn't trace this instruction.
6705001Sgblack@eecs.umich.edu                delete traceData;
6715001Sgblack@eecs.umich.edu                traceData = NULL;
6723170Sstever@eecs.umich.edu            }
6734998Sgblack@eecs.umich.edu
6742644Sstever@eecs.umich.edu            postExecute();
6755103Ssaidi@eecs.umich.edu            // @todo remove me after debugging with legion done
6765103Ssaidi@eecs.umich.edu            if (curStaticInst && (!curStaticInst->isMicroop() ||
6775103Ssaidi@eecs.umich.edu                        curStaticInst->isFirstMicroop()))
6785103Ssaidi@eecs.umich.edu                instCnt++;
6792644Sstever@eecs.umich.edu            advanceInst(fault);
6802644Sstever@eecs.umich.edu        }
6815726Sgblack@eecs.umich.edu    } else if (curStaticInst) {
6822623SN/A        // non-memory instruction: execute completely now
6832623SN/A        Fault fault = curStaticInst->execute(this, traceData);
6844998Sgblack@eecs.umich.edu
6854998Sgblack@eecs.umich.edu        // keep an instruction count
6864998Sgblack@eecs.umich.edu        if (fault == NoFault)
6874998Sgblack@eecs.umich.edu            countInst();
6887655Sali.saidi@arm.com        else if (traceData && !DTRACE(ExecFaulting)) {
6895001Sgblack@eecs.umich.edu            delete traceData;
6905001Sgblack@eecs.umich.edu            traceData = NULL;
6915001Sgblack@eecs.umich.edu        }
6924998Sgblack@eecs.umich.edu
6932644Sstever@eecs.umich.edu        postExecute();
6945103Ssaidi@eecs.umich.edu        // @todo remove me after debugging with legion done
6955103Ssaidi@eecs.umich.edu        if (curStaticInst && (!curStaticInst->isMicroop() ||
6965103Ssaidi@eecs.umich.edu                    curStaticInst->isFirstMicroop()))
6975103Ssaidi@eecs.umich.edu            instCnt++;
6982644Sstever@eecs.umich.edu        advanceInst(fault);
6995726Sgblack@eecs.umich.edu    } else {
7005726Sgblack@eecs.umich.edu        advanceInst(NoFault);
7012623SN/A    }
7023658Sktlim@umich.edu
7035669Sgblack@eecs.umich.edu    if (pkt) {
7045669Sgblack@eecs.umich.edu        delete pkt->req;
7055669Sgblack@eecs.umich.edu        delete pkt;
7065669Sgblack@eecs.umich.edu    }
7072623SN/A}
7082623SN/A
7092948Ssaidi@eecs.umich.eduvoid
7102948Ssaidi@eecs.umich.eduTimingSimpleCPU::IcachePort::ITickEvent::process()
7112948Ssaidi@eecs.umich.edu{
7122948Ssaidi@eecs.umich.edu    cpu->completeIfetch(pkt);
7132948Ssaidi@eecs.umich.edu}
7142623SN/A
7152623SN/Abool
7168975Sandreas.hansson@arm.comTimingSimpleCPU::IcachePort::recvTimingResp(PacketPtr pkt)
7172623SN/A{
7189165Sandreas.hansson@arm.com    DPRINTF(SimpleCPU, "Received timing response %#x\n", pkt->getAddr());
7199165Sandreas.hansson@arm.com    // delay processing of returned data until next CPU clock edge
7209165Sandreas.hansson@arm.com    Tick next_tick = cpu->nextCycle();
7212948Ssaidi@eecs.umich.edu
7229165Sandreas.hansson@arm.com    if (next_tick == curTick())
7239165Sandreas.hansson@arm.com        cpu->completeIfetch(pkt);
7249165Sandreas.hansson@arm.com    else
7259165Sandreas.hansson@arm.com        tickEvent.schedule(pkt, next_tick);
7268948Sandreas.hansson@arm.com
7274433Ssaidi@eecs.umich.edu    return true;
7282623SN/A}
7292623SN/A
7302657Ssaidi@eecs.umich.eduvoid
7312623SN/ATimingSimpleCPU::IcachePort::recvRetry()
7322623SN/A{
7332623SN/A    // we shouldn't get a retry unless we have a packet that we're
7342623SN/A    // waiting to transmit
7352623SN/A    assert(cpu->ifetch_pkt != NULL);
7362623SN/A    assert(cpu->_status == IcacheRetry);
7373349Sbinkertn@umich.edu    PacketPtr tmp = cpu->ifetch_pkt;
7388975Sandreas.hansson@arm.com    if (sendTimingReq(tmp)) {
7392657Ssaidi@eecs.umich.edu        cpu->_status = IcacheWaitResponse;
7402657Ssaidi@eecs.umich.edu        cpu->ifetch_pkt = NULL;
7412657Ssaidi@eecs.umich.edu    }
7422623SN/A}
7432623SN/A
7442623SN/Avoid
7453349Sbinkertn@umich.eduTimingSimpleCPU::completeDataAccess(PacketPtr pkt)
7462623SN/A{
7472623SN/A    // received a response from the dcache: complete the load or store
7482623SN/A    // instruction
7494870Sstever@eecs.umich.edu    assert(!pkt->isError());
7507516Shestness@cs.utexas.edu    assert(_status == DcacheWaitResponse || _status == DTBWaitResponse ||
7517516Shestness@cs.utexas.edu           pkt->req->getFlags().isSet(Request::NO_ACCESS));
7522623SN/A
7539179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
7549179Sandreas.hansson@arm.com    previousCycle = curCycle();
7553184Srdreslin@umich.edu
7565728Sgblack@eecs.umich.edu    if (pkt->senderState) {
7575728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
7585728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
7595728Sgblack@eecs.umich.edu        assert(send_state);
7605728Sgblack@eecs.umich.edu        delete pkt->req;
7615728Sgblack@eecs.umich.edu        delete pkt;
7625728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
7635728Sgblack@eecs.umich.edu        delete send_state;
7645728Sgblack@eecs.umich.edu
7655728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
7665728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
7675728Sgblack@eecs.umich.edu        assert(main_send_state);
7685728Sgblack@eecs.umich.edu        // Record the fact that this packet is no longer outstanding.
7695728Sgblack@eecs.umich.edu        assert(main_send_state->outstanding != 0);
7705728Sgblack@eecs.umich.edu        main_send_state->outstanding--;
7715728Sgblack@eecs.umich.edu
7725728Sgblack@eecs.umich.edu        if (main_send_state->outstanding) {
7735728Sgblack@eecs.umich.edu            return;
7745728Sgblack@eecs.umich.edu        } else {
7755728Sgblack@eecs.umich.edu            delete main_send_state;
7765728Sgblack@eecs.umich.edu            big_pkt->senderState = NULL;
7775728Sgblack@eecs.umich.edu            pkt = big_pkt;
7785728Sgblack@eecs.umich.edu        }
7795728Sgblack@eecs.umich.edu    }
7805728Sgblack@eecs.umich.edu
7815728Sgblack@eecs.umich.edu    _status = Running;
7825728Sgblack@eecs.umich.edu
7832623SN/A    Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
7842623SN/A
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
7945507Sstever@gmail.com    // the locked flag may be cleared on the response packet, so check
7955507Sstever@gmail.com    // pkt->req and not pkt to see if it was a load-locked
7966102Sgblack@eecs.umich.edu    if (pkt->isRead() && pkt->req->isLLSC()) {
7973170Sstever@eecs.umich.edu        TheISA::handleLockedRead(thread, pkt->req);
7983170Sstever@eecs.umich.edu    }
7993170Sstever@eecs.umich.edu
8002644Sstever@eecs.umich.edu    delete pkt->req;
8012644Sstever@eecs.umich.edu    delete pkt;
8022644Sstever@eecs.umich.edu
8033184Srdreslin@umich.edu    postExecute();
8043227Sktlim@umich.edu
8053201Shsul@eecs.umich.edu    if (getState() == SimObject::Draining) {
8063201Shsul@eecs.umich.edu        advancePC(fault);
8073201Shsul@eecs.umich.edu        completeDrain();
8083201Shsul@eecs.umich.edu
8093201Shsul@eecs.umich.edu        return;
8103201Shsul@eecs.umich.edu    }
8113201Shsul@eecs.umich.edu
8122644Sstever@eecs.umich.edu    advanceInst(fault);
8132623SN/A}
8142623SN/A
8152623SN/A
8162798Sktlim@umich.eduvoid
8172839Sktlim@umich.eduTimingSimpleCPU::completeDrain()
8182798Sktlim@umich.edu{
8199152Satgutier@umich.edu    DPRINTF(Drain, "CPU done draining, processing drain event\n");
8202901Ssaidi@eecs.umich.edu    changeState(SimObject::Drained);
8212839Sktlim@umich.edu    drainEvent->process();
8222798Sktlim@umich.edu}
8232623SN/A
8242623SN/Abool
8258975Sandreas.hansson@arm.comTimingSimpleCPU::DcachePort::recvTimingResp(PacketPtr pkt)
8262623SN/A{
8279165Sandreas.hansson@arm.com    // delay processing of returned data until next CPU clock edge
8289165Sandreas.hansson@arm.com    Tick next_tick = cpu->nextCycle();
8292948Ssaidi@eecs.umich.edu
8309165Sandreas.hansson@arm.com    if (next_tick == curTick()) {
8319165Sandreas.hansson@arm.com        cpu->completeDataAccess(pkt);
8329165Sandreas.hansson@arm.com    } else {
8339165Sandreas.hansson@arm.com        if (!tickEvent.scheduled()) {
8349165Sandreas.hansson@arm.com            tickEvent.schedule(pkt, next_tick);
8355728Sgblack@eecs.umich.edu        } else {
8369165Sandreas.hansson@arm.com            // In the case of a split transaction and a cache that is
8379165Sandreas.hansson@arm.com            // faster than a CPU we could get two responses before
8389165Sandreas.hansson@arm.com            // next_tick expires
8399165Sandreas.hansson@arm.com            if (!retryEvent.scheduled())
8409165Sandreas.hansson@arm.com                cpu->schedule(retryEvent, next_tick);
8419165Sandreas.hansson@arm.com            return false;
8424433Ssaidi@eecs.umich.edu        }
8433310Srdreslin@umich.edu    }
8448948Sandreas.hansson@arm.com
8454433Ssaidi@eecs.umich.edu    return true;
8462948Ssaidi@eecs.umich.edu}
8472948Ssaidi@eecs.umich.edu
8482948Ssaidi@eecs.umich.eduvoid
8492948Ssaidi@eecs.umich.eduTimingSimpleCPU::DcachePort::DTickEvent::process()
8502948Ssaidi@eecs.umich.edu{
8512630SN/A    cpu->completeDataAccess(pkt);
8522623SN/A}
8532623SN/A
8542657Ssaidi@eecs.umich.eduvoid
8552623SN/ATimingSimpleCPU::DcachePort::recvRetry()
8562623SN/A{
8572623SN/A    // we shouldn't get a retry unless we have a packet that we're
8582623SN/A    // waiting to transmit
8592623SN/A    assert(cpu->dcache_pkt != NULL);
8602623SN/A    assert(cpu->_status == DcacheRetry);
8613349Sbinkertn@umich.edu    PacketPtr tmp = cpu->dcache_pkt;
8625728Sgblack@eecs.umich.edu    if (tmp->senderState) {
8635728Sgblack@eecs.umich.edu        // This is a packet from a split access.
8645728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
8655728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(tmp->senderState);
8665728Sgblack@eecs.umich.edu        assert(send_state);
8675728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
8685728Sgblack@eecs.umich.edu
8695728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
8705728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
8715728Sgblack@eecs.umich.edu        assert(main_send_state);
8725728Sgblack@eecs.umich.edu
8738975Sandreas.hansson@arm.com        if (sendTimingReq(tmp)) {
8745728Sgblack@eecs.umich.edu            // If we were able to send without retrying, record that fact
8755728Sgblack@eecs.umich.edu            // and try sending the other fragment.
8765728Sgblack@eecs.umich.edu            send_state->clearFromParent();
8775728Sgblack@eecs.umich.edu            int other_index = main_send_state->getPendingFragment();
8785728Sgblack@eecs.umich.edu            if (other_index > 0) {
8795728Sgblack@eecs.umich.edu                tmp = main_send_state->fragments[other_index];
8805728Sgblack@eecs.umich.edu                cpu->dcache_pkt = tmp;
8815728Sgblack@eecs.umich.edu                if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) ||
8825728Sgblack@eecs.umich.edu                        (big_pkt->isWrite() && cpu->handleWritePacket())) {
8835728Sgblack@eecs.umich.edu                    main_send_state->fragments[other_index] = NULL;
8845728Sgblack@eecs.umich.edu                }
8855728Sgblack@eecs.umich.edu            } else {
8865728Sgblack@eecs.umich.edu                cpu->_status = DcacheWaitResponse;
8875728Sgblack@eecs.umich.edu                // memory system takes ownership of packet
8885728Sgblack@eecs.umich.edu                cpu->dcache_pkt = NULL;
8895728Sgblack@eecs.umich.edu            }
8905728Sgblack@eecs.umich.edu        }
8918975Sandreas.hansson@arm.com    } else if (sendTimingReq(tmp)) {
8922657Ssaidi@eecs.umich.edu        cpu->_status = DcacheWaitResponse;
8933170Sstever@eecs.umich.edu        // memory system takes ownership of packet
8942657Ssaidi@eecs.umich.edu        cpu->dcache_pkt = NULL;
8952657Ssaidi@eecs.umich.edu    }
8962623SN/A}
8972623SN/A
8985606Snate@binkert.orgTimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu,
8995606Snate@binkert.org    Tick t)
9005606Snate@binkert.org    : pkt(_pkt), cpu(_cpu)
9015103Ssaidi@eecs.umich.edu{
9025606Snate@binkert.org    cpu->schedule(this, t);
9035103Ssaidi@eecs.umich.edu}
9045103Ssaidi@eecs.umich.edu
9055103Ssaidi@eecs.umich.eduvoid
9065103Ssaidi@eecs.umich.eduTimingSimpleCPU::IprEvent::process()
9075103Ssaidi@eecs.umich.edu{
9085103Ssaidi@eecs.umich.edu    cpu->completeDataAccess(pkt);
9095103Ssaidi@eecs.umich.edu}
9105103Ssaidi@eecs.umich.edu
9115103Ssaidi@eecs.umich.educonst char *
9125336Shines@cs.fsu.eduTimingSimpleCPU::IprEvent::description() const
9135103Ssaidi@eecs.umich.edu{
9145103Ssaidi@eecs.umich.edu    return "Timing Simple CPU Delay IPR event";
9155103Ssaidi@eecs.umich.edu}
9165103Ssaidi@eecs.umich.edu
9172623SN/A
9185315Sstever@gmail.comvoid
9195315Sstever@gmail.comTimingSimpleCPU::printAddr(Addr a)
9205315Sstever@gmail.com{
9215315Sstever@gmail.com    dcachePort.printAddr(a);
9225315Sstever@gmail.com}
9235315Sstever@gmail.com
9245315Sstever@gmail.com
9252623SN/A////////////////////////////////////////////////////////////////////////
9262623SN/A//
9272623SN/A//  TimingSimpleCPU Simulation Object
9282623SN/A//
9294762Snate@binkert.orgTimingSimpleCPU *
9304762Snate@binkert.orgTimingSimpleCPUParams::create()
9312623SN/A{
9325529Snate@binkert.org    numThreads = 1;
9338779Sgblack@eecs.umich.edu    if (!FullSystem && workload.size() != 1)
9344762Snate@binkert.org        panic("only one workload allowed");
9355529Snate@binkert.org    return new TimingSimpleCPU(this);
9362623SN/A}
937