timing.cc revision 10529
12623SN/A/*
210030SAli.Saidi@ARM.com * Copyright (c) 2010-2013 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
6110529Smorr@cs.wisc.edu#include "debug/Mwait.hh"
6210529Smorr@cs.wisc.edu
632623SN/Ausing namespace std;
642623SN/Ausing namespace TheISA;
652623SN/A
662623SN/Avoid
672623SN/ATimingSimpleCPU::init()
682623SN/A{
692623SN/A    BaseCPU::init();
708921Sandreas.hansson@arm.com
718921Sandreas.hansson@arm.com    // Initialise the ThreadContext's memory proxies
728921Sandreas.hansson@arm.com    tcBase()->initMemProxies(tcBase());
738921Sandreas.hansson@arm.com
749433SAndreas.Sandberg@ARM.com    if (FullSystem && !params()->switched_out) {
758779Sgblack@eecs.umich.edu        for (int i = 0; i < threadContexts.size(); ++i) {
768779Sgblack@eecs.umich.edu            ThreadContext *tc = threadContexts[i];
778779Sgblack@eecs.umich.edu            // initialize CPU, including PC
788779Sgblack@eecs.umich.edu            TheISA::initCPU(tc, _cpuId);
798779Sgblack@eecs.umich.edu        }
802623SN/A    }
812623SN/A}
822623SN/A
832623SN/Avoid
848707Sandreas.hansson@arm.comTimingSimpleCPU::TimingCPUPort::TickEvent::schedule(PacketPtr _pkt, Tick t)
852948Ssaidi@eecs.umich.edu{
862948Ssaidi@eecs.umich.edu    pkt = _pkt;
875606Snate@binkert.org    cpu->schedule(this, t);
882948Ssaidi@eecs.umich.edu}
892948Ssaidi@eecs.umich.edu
905529Snate@binkert.orgTimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p)
918707Sandreas.hansson@arm.com    : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this),
929179Sandreas.hansson@arm.com      dcachePort(this), ifetch_pkt(NULL), dcache_pkt(NULL), previousCycle(0),
939442SAndreas.Sandberg@ARM.com      fetchEvent(this), drainManager(NULL)
942623SN/A{
952623SN/A    _status = Idle;
963647Srdreslin@umich.edu
977897Shestness@cs.utexas.edu    system->totalNumInsts = 0;
982623SN/A}
992623SN/A
1002623SN/A
10110030SAli.Saidi@ARM.com
1022623SN/ATimingSimpleCPU::~TimingSimpleCPU()
1032623SN/A{
1042623SN/A}
1052623SN/A
1062901Ssaidi@eecs.umich.eduunsigned int
1079342SAndreas.Sandberg@arm.comTimingSimpleCPU::drain(DrainManager *drain_manager)
1082798Sktlim@umich.edu{
1099448SAndreas.Sandberg@ARM.com    assert(!drainManager);
1109448SAndreas.Sandberg@ARM.com    if (switchedOut())
1119448SAndreas.Sandberg@ARM.com        return 0;
1129448SAndreas.Sandberg@ARM.com
1139342SAndreas.Sandberg@arm.com    if (_status == Idle ||
1149448SAndreas.Sandberg@ARM.com        (_status == BaseSimpleCPU::Running && isDrained())) {
1159442SAndreas.Sandberg@ARM.com        DPRINTF(Drain, "No need to drain.\n");
1162901Ssaidi@eecs.umich.edu        return 0;
1172798Sktlim@umich.edu    } else {
1189342SAndreas.Sandberg@arm.com        drainManager = drain_manager;
1199442SAndreas.Sandberg@ARM.com        DPRINTF(Drain, "Requesting drain: %s\n", pcState());
1209442SAndreas.Sandberg@ARM.com
1219442SAndreas.Sandberg@ARM.com        // The fetch event can become descheduled if a drain didn't
1229442SAndreas.Sandberg@ARM.com        // succeed on the first attempt. We need to reschedule it if
1239442SAndreas.Sandberg@ARM.com        // the CPU is waiting for a microcode routine to complete.
1249448SAndreas.Sandberg@ARM.com        if (_status == BaseSimpleCPU::Running && !fetchEvent.scheduled())
1259648Sdam.sunwoo@arm.com            schedule(fetchEvent, clockEdge());
1269442SAndreas.Sandberg@ARM.com
1272901Ssaidi@eecs.umich.edu        return 1;
1282798Sktlim@umich.edu    }
1292623SN/A}
1302623SN/A
1312623SN/Avoid
1329342SAndreas.Sandberg@arm.comTimingSimpleCPU::drainResume()
1332623SN/A{
1349442SAndreas.Sandberg@ARM.com    assert(!fetchEvent.scheduled());
1359448SAndreas.Sandberg@ARM.com    assert(!drainManager);
1369448SAndreas.Sandberg@ARM.com    if (switchedOut())
1379448SAndreas.Sandberg@ARM.com        return;
1389442SAndreas.Sandberg@ARM.com
1395221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Resume\n");
1409523SAndreas.Sandberg@ARM.com    verifyMemoryMode();
1413201Shsul@eecs.umich.edu
1429448SAndreas.Sandberg@ARM.com    assert(!threadContexts.empty());
1439448SAndreas.Sandberg@ARM.com    if (threadContexts.size() > 1)
1449448SAndreas.Sandberg@ARM.com        fatal("The timing CPU only supports one thread.\n");
1459448SAndreas.Sandberg@ARM.com
1469448SAndreas.Sandberg@ARM.com    if (thread->status() == ThreadContext::Active) {
1475710Scws3k@cs.virginia.edu        schedule(fetchEvent, nextCycle());
1489448SAndreas.Sandberg@ARM.com        _status = BaseSimpleCPU::Running;
1499837Slena@cs.wisc,edu        notIdleFraction = 1;
1509448SAndreas.Sandberg@ARM.com    } else {
1519448SAndreas.Sandberg@ARM.com        _status = BaseSimpleCPU::Idle;
1529837Slena@cs.wisc,edu        notIdleFraction = 0;
1532623SN/A    }
1549442SAndreas.Sandberg@ARM.com}
1552798Sktlim@umich.edu
1569442SAndreas.Sandberg@ARM.combool
1579442SAndreas.Sandberg@ARM.comTimingSimpleCPU::tryCompleteDrain()
1589442SAndreas.Sandberg@ARM.com{
1599442SAndreas.Sandberg@ARM.com    if (!drainManager)
1609442SAndreas.Sandberg@ARM.com        return false;
1619442SAndreas.Sandberg@ARM.com
1629442SAndreas.Sandberg@ARM.com    DPRINTF(Drain, "tryCompleteDrain: %s\n", pcState());
1639442SAndreas.Sandberg@ARM.com    if (!isDrained())
1649442SAndreas.Sandberg@ARM.com        return false;
1659442SAndreas.Sandberg@ARM.com
1669442SAndreas.Sandberg@ARM.com    DPRINTF(Drain, "CPU done draining, processing drain event\n");
1679442SAndreas.Sandberg@ARM.com    drainManager->signalDrainDone();
1689442SAndreas.Sandberg@ARM.com    drainManager = NULL;
1699442SAndreas.Sandberg@ARM.com
1709442SAndreas.Sandberg@ARM.com    return true;
1712798Sktlim@umich.edu}
1722798Sktlim@umich.edu
1732798Sktlim@umich.eduvoid
1742798Sktlim@umich.eduTimingSimpleCPU::switchOut()
1752798Sktlim@umich.edu{
1769429SAndreas.Sandberg@ARM.com    BaseSimpleCPU::switchOut();
1779429SAndreas.Sandberg@ARM.com
1789442SAndreas.Sandberg@ARM.com    assert(!fetchEvent.scheduled());
1799342SAndreas.Sandberg@arm.com    assert(_status == BaseSimpleCPU::Running || _status == Idle);
1809442SAndreas.Sandberg@ARM.com    assert(!stayAtPC);
1819442SAndreas.Sandberg@ARM.com    assert(microPC() == 0);
1829442SAndreas.Sandberg@ARM.com
18310464SAndreas.Sandberg@ARM.com    updateCycleCounts();
1842623SN/A}
1852623SN/A
1862623SN/A
1872623SN/Avoid
1882623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
1892623SN/A{
1909429SAndreas.Sandberg@ARM.com    BaseSimpleCPU::takeOverFrom(oldCPU);
1912623SN/A
1929179Sandreas.hansson@arm.com    previousCycle = curCycle();
1932623SN/A}
1942623SN/A
1959523SAndreas.Sandberg@ARM.comvoid
1969523SAndreas.Sandberg@ARM.comTimingSimpleCPU::verifyMemoryMode() const
1979523SAndreas.Sandberg@ARM.com{
1989524SAndreas.Sandberg@ARM.com    if (!system->isTimingMode()) {
1999523SAndreas.Sandberg@ARM.com        fatal("The timing CPU requires the memory system to be in "
2009523SAndreas.Sandberg@ARM.com              "'timing' mode.\n");
2019523SAndreas.Sandberg@ARM.com    }
2029523SAndreas.Sandberg@ARM.com}
2032623SN/A
2042623SN/Avoid
20510407Smitch.hayenga@arm.comTimingSimpleCPU::activateContext(ThreadID thread_num)
2062623SN/A{
20710407Smitch.hayenga@arm.com    DPRINTF(SimpleCPU, "ActivateContext %d\n", thread_num);
2085221Ssaidi@eecs.umich.edu
2092623SN/A    assert(thread_num == 0);
2102683Sktlim@umich.edu    assert(thread);
2112623SN/A
2122623SN/A    assert(_status == Idle);
2132623SN/A
2149837Slena@cs.wisc,edu    notIdleFraction = 1;
2159342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
2163686Sktlim@umich.edu
2172623SN/A    // kick things off by initiating the fetch of the next instruction
21810407Smitch.hayenga@arm.com    schedule(fetchEvent, clockEdge(Cycles(0)));
2192623SN/A}
2202623SN/A
2212623SN/A
2222623SN/Avoid
2238737Skoansin.tan@gmail.comTimingSimpleCPU::suspendContext(ThreadID thread_num)
2242623SN/A{
2255221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
2265221Ssaidi@eecs.umich.edu
2272623SN/A    assert(thread_num == 0);
2282683Sktlim@umich.edu    assert(thread);
2292623SN/A
2306043Sgblack@eecs.umich.edu    if (_status == Idle)
2316043Sgblack@eecs.umich.edu        return;
2326043Sgblack@eecs.umich.edu
2339342SAndreas.Sandberg@arm.com    assert(_status == BaseSimpleCPU::Running);
2342623SN/A
2352644Sstever@eecs.umich.edu    // just change status to Idle... if status != Running,
2362644Sstever@eecs.umich.edu    // completeInst() will not initiate fetch of next instruction.
2372623SN/A
2389837Slena@cs.wisc,edu    notIdleFraction = 0;
2392623SN/A    _status = Idle;
2402623SN/A}
2412623SN/A
2425728Sgblack@eecs.umich.edubool
2435728Sgblack@eecs.umich.eduTimingSimpleCPU::handleReadPacket(PacketPtr pkt)
2445728Sgblack@eecs.umich.edu{
2455728Sgblack@eecs.umich.edu    RequestPtr req = pkt->req;
2468105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
2479180Sandreas.hansson@arm.com        Cycles delay = TheISA::handleIprRead(thread->getTC(), pkt);
2489179Sandreas.hansson@arm.com        new IprEvent(pkt, this, clockEdge(delay));
2495728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2505728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2518975Sandreas.hansson@arm.com    } else if (!dcachePort.sendTimingReq(pkt)) {
2525728Sgblack@eecs.umich.edu        _status = DcacheRetry;
2535728Sgblack@eecs.umich.edu        dcache_pkt = pkt;
2545728Sgblack@eecs.umich.edu    } else {
2555728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2565728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
2575728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2585728Sgblack@eecs.umich.edu    }
2595728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
2605728Sgblack@eecs.umich.edu}
2612623SN/A
2625894Sgblack@eecs.umich.eduvoid
2636973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
2646973Stjones1@inf.ed.ac.uk                          bool read)
2655744Sgblack@eecs.umich.edu{
2665894Sgblack@eecs.umich.edu    PacketPtr pkt;
2675894Sgblack@eecs.umich.edu    buildPacket(pkt, req, read);
2687691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
2695894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2705894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2715894Sgblack@eecs.umich.edu        pkt->makeResponse();
2725894Sgblack@eecs.umich.edu        completeDataAccess(pkt);
2735894Sgblack@eecs.umich.edu    } else if (read) {
2745894Sgblack@eecs.umich.edu        handleReadPacket(pkt);
2755894Sgblack@eecs.umich.edu    } else {
2765894Sgblack@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
2775894Sgblack@eecs.umich.edu
2786102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
27910030SAli.Saidi@ARM.com            do_access = TheISA::handleLockedWrite(thread, req, dcachePort.cacheBlockMask);
2805894Sgblack@eecs.umich.edu        } else if (req->isCondSwap()) {
2815894Sgblack@eecs.umich.edu            assert(res);
2825894Sgblack@eecs.umich.edu            req->setExtraData(*res);
2835894Sgblack@eecs.umich.edu        }
2845894Sgblack@eecs.umich.edu
2855894Sgblack@eecs.umich.edu        if (do_access) {
2865894Sgblack@eecs.umich.edu            dcache_pkt = pkt;
2875894Sgblack@eecs.umich.edu            handleWritePacket();
2885894Sgblack@eecs.umich.edu        } else {
2895894Sgblack@eecs.umich.edu            _status = DcacheWaitResponse;
2905894Sgblack@eecs.umich.edu            completeDataAccess(pkt);
2915894Sgblack@eecs.umich.edu        }
2925894Sgblack@eecs.umich.edu    }
2935894Sgblack@eecs.umich.edu}
2945894Sgblack@eecs.umich.edu
2955894Sgblack@eecs.umich.eduvoid
2966973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendSplitData(RequestPtr req1, RequestPtr req2,
2976973Stjones1@inf.ed.ac.uk                               RequestPtr req, uint8_t *data, bool read)
2985894Sgblack@eecs.umich.edu{
2995894Sgblack@eecs.umich.edu    PacketPtr pkt1, pkt2;
3005894Sgblack@eecs.umich.edu    buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
3015894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3025894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
3035894Sgblack@eecs.umich.edu        pkt1->makeResponse();
3045894Sgblack@eecs.umich.edu        completeDataAccess(pkt1);
3055894Sgblack@eecs.umich.edu    } else if (read) {
3067911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
3077911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3085894Sgblack@eecs.umich.edu        if (handleReadPacket(pkt1)) {
3095894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3107911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
3117911Shestness@cs.utexas.edu                    pkt2->senderState);
3125894Sgblack@eecs.umich.edu            if (handleReadPacket(pkt2)) {
3135894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3145894Sgblack@eecs.umich.edu            }
3155894Sgblack@eecs.umich.edu        }
3165894Sgblack@eecs.umich.edu    } else {
3175894Sgblack@eecs.umich.edu        dcache_pkt = pkt1;
3187911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
3197911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3205894Sgblack@eecs.umich.edu        if (handleWritePacket()) {
3215894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3225894Sgblack@eecs.umich.edu            dcache_pkt = pkt2;
3237911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
3247911Shestness@cs.utexas.edu                    pkt2->senderState);
3255894Sgblack@eecs.umich.edu            if (handleWritePacket()) {
3265894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3275894Sgblack@eecs.umich.edu            }
3285894Sgblack@eecs.umich.edu        }
3295894Sgblack@eecs.umich.edu    }
3305894Sgblack@eecs.umich.edu}
3315894Sgblack@eecs.umich.edu
3325894Sgblack@eecs.umich.eduvoid
33310379Sandreas.hansson@arm.comTimingSimpleCPU::translationFault(const Fault &fault)
3345894Sgblack@eecs.umich.edu{
3356739Sgblack@eecs.umich.edu    // fault may be NoFault in cases where a fault is suppressed,
3366739Sgblack@eecs.umich.edu    // for instance prefetches.
33710464SAndreas.Sandberg@ARM.com    updateCycleCounts();
3385894Sgblack@eecs.umich.edu
3395894Sgblack@eecs.umich.edu    if (traceData) {
3405894Sgblack@eecs.umich.edu        // Since there was a fault, we shouldn't trace this instruction.
3415894Sgblack@eecs.umich.edu        delete traceData;
3425894Sgblack@eecs.umich.edu        traceData = NULL;
3435744Sgblack@eecs.umich.edu    }
3445744Sgblack@eecs.umich.edu
3455894Sgblack@eecs.umich.edu    postExecute();
3465894Sgblack@eecs.umich.edu
3479442SAndreas.Sandberg@ARM.com    advanceInst(fault);
3485894Sgblack@eecs.umich.edu}
3495894Sgblack@eecs.umich.edu
3505894Sgblack@eecs.umich.eduvoid
3515894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
3525894Sgblack@eecs.umich.edu{
35310342SCurtis.Dunham@arm.com    pkt = read ? Packet::createRead(req) : Packet::createWrite(req);
3545894Sgblack@eecs.umich.edu}
3555894Sgblack@eecs.umich.edu
3565894Sgblack@eecs.umich.eduvoid
3575894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
3585894Sgblack@eecs.umich.edu        RequestPtr req1, RequestPtr req2, RequestPtr req,
3595894Sgblack@eecs.umich.edu        uint8_t *data, bool read)
3605894Sgblack@eecs.umich.edu{
3615894Sgblack@eecs.umich.edu    pkt1 = pkt2 = NULL;
3625894Sgblack@eecs.umich.edu
3638105Sgblack@eecs.umich.edu    assert(!req1->isMmappedIpr() && !req2->isMmappedIpr());
3645744Sgblack@eecs.umich.edu
3655894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3665894Sgblack@eecs.umich.edu        buildPacket(pkt1, req, read);
3675894Sgblack@eecs.umich.edu        return;
3685894Sgblack@eecs.umich.edu    }
3695894Sgblack@eecs.umich.edu
3705894Sgblack@eecs.umich.edu    buildPacket(pkt1, req1, read);
3715894Sgblack@eecs.umich.edu    buildPacket(pkt2, req2, read);
3725894Sgblack@eecs.umich.edu
3738832SAli.Saidi@ARM.com    req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags(), dataMasterId());
3748949Sandreas.hansson@arm.com    PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand());
3755744Sgblack@eecs.umich.edu
3767691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
3775744Sgblack@eecs.umich.edu    pkt1->dataStatic<uint8_t>(data);
3785744Sgblack@eecs.umich.edu    pkt2->dataStatic<uint8_t>(data + req1->getSize());
3795744Sgblack@eecs.umich.edu
3805744Sgblack@eecs.umich.edu    SplitMainSenderState * main_send_state = new SplitMainSenderState;
3815744Sgblack@eecs.umich.edu    pkt->senderState = main_send_state;
3825744Sgblack@eecs.umich.edu    main_send_state->fragments[0] = pkt1;
3835744Sgblack@eecs.umich.edu    main_send_state->fragments[1] = pkt2;
3845744Sgblack@eecs.umich.edu    main_send_state->outstanding = 2;
3855744Sgblack@eecs.umich.edu    pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
3865744Sgblack@eecs.umich.edu    pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
3875744Sgblack@eecs.umich.edu}
3885744Sgblack@eecs.umich.edu
3892623SN/AFault
3908444Sgblack@eecs.umich.eduTimingSimpleCPU::readMem(Addr addr, uint8_t *data,
3918444Sgblack@eecs.umich.edu                         unsigned size, unsigned flags)
3922623SN/A{
3935728Sgblack@eecs.umich.edu    Fault fault;
3945728Sgblack@eecs.umich.edu    const int asid = 0;
3956221Snate@binkert.org    const ThreadID tid = 0;
3967720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
3979814Sandreas.hansson@arm.com    unsigned block_size = cacheLineSize();
3986973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Read;
3992623SN/A
4007045Ssteve.reinhardt@amd.com    if (traceData) {
4017045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4027045Ssteve.reinhardt@amd.com    }
4037045Ssteve.reinhardt@amd.com
4047520Sgblack@eecs.umich.edu    RequestPtr req  = new Request(asid, addr, size,
4058832SAli.Saidi@ARM.com                                  flags, dataMasterId(), pc, _cpuId, tid);
4065728Sgblack@eecs.umich.edu
40710024Sdam.sunwoo@arm.com    req->taskId(taskId());
40810024Sdam.sunwoo@arm.com
4097520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4105744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4115728Sgblack@eecs.umich.edu
4125894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4135744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4145894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4156102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4165894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4175894Sgblack@eecs.umich.edu
4186973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4197520Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, new uint8_t[size],
4206973Stjones1@inf.ed.ac.uk                                      NULL, mode);
4218486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4228486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4238486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
4248486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
4256973Stjones1@inf.ed.ac.uk
4266973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
4276973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
4285744Sgblack@eecs.umich.edu    } else {
4296973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4307520Sgblack@eecs.umich.edu            new WholeTranslationState(req, new uint8_t[size], NULL, mode);
4318486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation
4328486Sgblack@eecs.umich.edu            = new DataTranslation<TimingSimpleCPU *>(this, state);
4336973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
4342623SN/A    }
4352623SN/A
4365728Sgblack@eecs.umich.edu    return NoFault;
4372623SN/A}
4382623SN/A
4395728Sgblack@eecs.umich.edubool
4405728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket()
4415728Sgblack@eecs.umich.edu{
4425728Sgblack@eecs.umich.edu    RequestPtr req = dcache_pkt->req;
4438105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
4449180Sandreas.hansson@arm.com        Cycles delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
4459179Sandreas.hansson@arm.com        new IprEvent(dcache_pkt, this, clockEdge(delay));
4465728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4475728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4488975Sandreas.hansson@arm.com    } else if (!dcachePort.sendTimingReq(dcache_pkt)) {
4495728Sgblack@eecs.umich.edu        _status = DcacheRetry;
4505728Sgblack@eecs.umich.edu    } else {
4515728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4525728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
4535728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4545728Sgblack@eecs.umich.edu    }
4555728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
4565728Sgblack@eecs.umich.edu}
4572623SN/A
4582623SN/AFault
4598444Sgblack@eecs.umich.eduTimingSimpleCPU::writeMem(uint8_t *data, unsigned size,
4608444Sgblack@eecs.umich.edu                          Addr addr, unsigned flags, uint64_t *res)
4612623SN/A{
4628443Sgblack@eecs.umich.edu    uint8_t *newData = new uint8_t[size];
4635728Sgblack@eecs.umich.edu    const int asid = 0;
4646221Snate@binkert.org    const ThreadID tid = 0;
4657720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4669814Sandreas.hansson@arm.com    unsigned block_size = cacheLineSize();
4676973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Write;
4683169Sstever@eecs.umich.edu
46910031SAli.Saidi@ARM.com    if (data == NULL) {
47010031SAli.Saidi@ARM.com        assert(flags & Request::CACHE_BLOCK_ZERO);
47110031SAli.Saidi@ARM.com        // This must be a cache block cleaning request
47210031SAli.Saidi@ARM.com        memset(newData, 0, size);
47310031SAli.Saidi@ARM.com    } else {
47410031SAli.Saidi@ARM.com        memcpy(newData, data, size);
47510031SAli.Saidi@ARM.com    }
47610031SAli.Saidi@ARM.com
4777045Ssteve.reinhardt@amd.com    if (traceData) {
4787045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4797045Ssteve.reinhardt@amd.com    }
4807045Ssteve.reinhardt@amd.com
4817520Sgblack@eecs.umich.edu    RequestPtr req = new Request(asid, addr, size,
4828832SAli.Saidi@ARM.com                                 flags, dataMasterId(), pc, _cpuId, tid);
4835728Sgblack@eecs.umich.edu
48410024Sdam.sunwoo@arm.com    req->taskId(taskId());
48510024Sdam.sunwoo@arm.com
4867520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4875744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4885728Sgblack@eecs.umich.edu
4895894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4905744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4915894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4926102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4935894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4945894Sgblack@eecs.umich.edu
4956973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4968443Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, newData, res, mode);
4978486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4988486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4998486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
5008486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
5016973Stjones1@inf.ed.ac.uk
5026973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
5036973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
5045744Sgblack@eecs.umich.edu    } else {
5056973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
5068443Sgblack@eecs.umich.edu            new WholeTranslationState(req, newData, res, mode);
5078486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation =
5088486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state);
5096973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
5102623SN/A    }
5112623SN/A
5127045Ssteve.reinhardt@amd.com    // Translation faults will be returned via finishTranslation()
5135728Sgblack@eecs.umich.edu    return NoFault;
5142623SN/A}
5152623SN/A
5162623SN/A
5172623SN/Avoid
5186973Stjones1@inf.ed.ac.ukTimingSimpleCPU::finishTranslation(WholeTranslationState *state)
5196973Stjones1@inf.ed.ac.uk{
5209342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
5216973Stjones1@inf.ed.ac.uk
5226973Stjones1@inf.ed.ac.uk    if (state->getFault() != NoFault) {
5236973Stjones1@inf.ed.ac.uk        if (state->isPrefetch()) {
5246973Stjones1@inf.ed.ac.uk            state->setNoFault();
5256973Stjones1@inf.ed.ac.uk        }
5267691SAli.Saidi@ARM.com        delete [] state->data;
5276973Stjones1@inf.ed.ac.uk        state->deleteReqs();
5286973Stjones1@inf.ed.ac.uk        translationFault(state->getFault());
5296973Stjones1@inf.ed.ac.uk    } else {
5306973Stjones1@inf.ed.ac.uk        if (!state->isSplit) {
5316973Stjones1@inf.ed.ac.uk            sendData(state->mainReq, state->data, state->res,
5326973Stjones1@inf.ed.ac.uk                     state->mode == BaseTLB::Read);
5336973Stjones1@inf.ed.ac.uk        } else {
5346973Stjones1@inf.ed.ac.uk            sendSplitData(state->sreqLow, state->sreqHigh, state->mainReq,
5356973Stjones1@inf.ed.ac.uk                          state->data, state->mode == BaseTLB::Read);
5366973Stjones1@inf.ed.ac.uk        }
5376973Stjones1@inf.ed.ac.uk    }
5386973Stjones1@inf.ed.ac.uk
5396973Stjones1@inf.ed.ac.uk    delete state;
5406973Stjones1@inf.ed.ac.uk}
5416973Stjones1@inf.ed.ac.uk
5426973Stjones1@inf.ed.ac.uk
5436973Stjones1@inf.ed.ac.ukvoid
5442623SN/ATimingSimpleCPU::fetch()
5452623SN/A{
5465221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Fetch\n");
5475221Ssaidi@eecs.umich.edu
5483387Sgblack@eecs.umich.edu    if (!curStaticInst || !curStaticInst->isDelayedCommit())
5493387Sgblack@eecs.umich.edu        checkForInterrupts();
5502631SN/A
5515348Ssaidi@eecs.umich.edu    checkPcEventQueue();
5525348Ssaidi@eecs.umich.edu
5538143SAli.Saidi@ARM.com    // We must have just got suspended by a PC event
5548143SAli.Saidi@ARM.com    if (_status == Idle)
5558143SAli.Saidi@ARM.com        return;
5568143SAli.Saidi@ARM.com
5577720Sgblack@eecs.umich.edu    TheISA::PCState pcState = thread->pcState();
5587720Sgblack@eecs.umich.edu    bool needToFetch = !isRomMicroPC(pcState.microPC()) && !curMacroStaticInst;
5592623SN/A
5607720Sgblack@eecs.umich.edu    if (needToFetch) {
5619342SAndreas.Sandberg@arm.com        _status = BaseSimpleCPU::Running;
5625669Sgblack@eecs.umich.edu        Request *ifetch_req = new Request();
56310024Sdam.sunwoo@arm.com        ifetch_req->taskId(taskId());
5645712Shsul@eecs.umich.edu        ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0);
5655894Sgblack@eecs.umich.edu        setupFetchRequest(ifetch_req);
5668277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translating address %#x\n", ifetch_req->getVaddr());
5676023Snate@binkert.org        thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation,
5686023Snate@binkert.org                BaseTLB::Execute);
5692623SN/A    } else {
5705669Sgblack@eecs.umich.edu        _status = IcacheWaitResponse;
5715669Sgblack@eecs.umich.edu        completeIfetch(NULL);
5725894Sgblack@eecs.umich.edu
57310464SAndreas.Sandberg@ARM.com        updateCycleCounts();
5745894Sgblack@eecs.umich.edu    }
5755894Sgblack@eecs.umich.edu}
5765894Sgblack@eecs.umich.edu
5775894Sgblack@eecs.umich.edu
5785894Sgblack@eecs.umich.eduvoid
57910379Sandreas.hansson@arm.comTimingSimpleCPU::sendFetch(const Fault &fault, RequestPtr req,
58010379Sandreas.hansson@arm.com                           ThreadContext *tc)
5815894Sgblack@eecs.umich.edu{
5825894Sgblack@eecs.umich.edu    if (fault == NoFault) {
5838277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Sending fetch for addr %#x(pa: %#x)\n",
5848277SAli.Saidi@ARM.com                req->getVaddr(), req->getPaddr());
5858949Sandreas.hansson@arm.com        ifetch_pkt = new Packet(req, MemCmd::ReadReq);
5865894Sgblack@eecs.umich.edu        ifetch_pkt->dataStatic(&inst);
5878277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, " -- pkt addr: %#x\n", ifetch_pkt->getAddr());
5885894Sgblack@eecs.umich.edu
5898975Sandreas.hansson@arm.com        if (!icachePort.sendTimingReq(ifetch_pkt)) {
5905894Sgblack@eecs.umich.edu            // Need to wait for retry
5915894Sgblack@eecs.umich.edu            _status = IcacheRetry;
5925894Sgblack@eecs.umich.edu        } else {
5935894Sgblack@eecs.umich.edu            // Need to wait for cache to respond
5945894Sgblack@eecs.umich.edu            _status = IcacheWaitResponse;
5955894Sgblack@eecs.umich.edu            // ownership of packet transferred to memory system
5965894Sgblack@eecs.umich.edu            ifetch_pkt = NULL;
5975894Sgblack@eecs.umich.edu        }
5985894Sgblack@eecs.umich.edu    } else {
5998277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translation of addr %#x faulted\n", req->getVaddr());
6005894Sgblack@eecs.umich.edu        delete req;
6015894Sgblack@eecs.umich.edu        // fetch fault: advance directly to next instruction (fault handler)
6029342SAndreas.Sandberg@arm.com        _status = BaseSimpleCPU::Running;
6035894Sgblack@eecs.umich.edu        advanceInst(fault);
6042623SN/A    }
6053222Sktlim@umich.edu
60610464SAndreas.Sandberg@ARM.com    updateCycleCounts();
6072623SN/A}
6082623SN/A
6092623SN/A
6102623SN/Avoid
61110379Sandreas.hansson@arm.comTimingSimpleCPU::advanceInst(const Fault &fault)
6122623SN/A{
6138276SAli.Saidi@ARM.com    if (_status == Faulting)
6148276SAli.Saidi@ARM.com        return;
6158276SAli.Saidi@ARM.com
6168276SAli.Saidi@ARM.com    if (fault != NoFault) {
6178276SAli.Saidi@ARM.com        advancePC(fault);
6188276SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Fault occured, scheduling fetch event\n");
6199648Sdam.sunwoo@arm.com        reschedule(fetchEvent, clockEdge(), true);
6208276SAli.Saidi@ARM.com        _status = Faulting;
6218276SAli.Saidi@ARM.com        return;
6228276SAli.Saidi@ARM.com    }
6238276SAli.Saidi@ARM.com
6248276SAli.Saidi@ARM.com
6258276SAli.Saidi@ARM.com    if (!stayAtPC)
6265726Sgblack@eecs.umich.edu        advancePC(fault);
6272623SN/A
6289442SAndreas.Sandberg@ARM.com    if (tryCompleteDrain())
6299442SAndreas.Sandberg@ARM.com            return;
6309442SAndreas.Sandberg@ARM.com
6319342SAndreas.Sandberg@arm.com    if (_status == BaseSimpleCPU::Running) {
6322631SN/A        // kick off fetch of next instruction... callback from icache
6332631SN/A        // response will cause that instruction to be executed,
6342631SN/A        // keeping the CPU running.
6352631SN/A        fetch();
6362631SN/A    }
6372623SN/A}
6382623SN/A
6392623SN/A
6402623SN/Avoid
6413349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt)
6422623SN/A{
6438277SAli.Saidi@ARM.com    DPRINTF(SimpleCPU, "Complete ICache Fetch for addr %#x\n", pkt ?
6448277SAli.Saidi@ARM.com            pkt->getAddr() : 0);
6458277SAli.Saidi@ARM.com
6462623SN/A    // received a response from the icache: execute the received
6472623SN/A    // instruction
6485669Sgblack@eecs.umich.edu    assert(!pkt || !pkt->isError());
6492623SN/A    assert(_status == IcacheWaitResponse);
6502798Sktlim@umich.edu
6519342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
6522644Sstever@eecs.umich.edu
65310464SAndreas.Sandberg@ARM.com    updateCycleCounts();
6543222Sktlim@umich.edu
65510020Smatt.horsnell@ARM.com    if (pkt)
65610020Smatt.horsnell@ARM.com        pkt->req->setAccessLatency();
65710020Smatt.horsnell@ARM.com
65810020Smatt.horsnell@ARM.com
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
6679342SAndreas.Sandberg@arm.com        if (_status == BaseSimpleCPU::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
7209648Sdam.sunwoo@arm.com    Tick next_tick = cpu->clockEdge();
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
75310020Smatt.horsnell@ARM.com    pkt->req->setAccessLatency();
75410464SAndreas.Sandberg@ARM.com
75510464SAndreas.Sandberg@ARM.com    updateCycleCounts();
7563184Srdreslin@umich.edu
7575728Sgblack@eecs.umich.edu    if (pkt->senderState) {
7585728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
7595728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
7605728Sgblack@eecs.umich.edu        assert(send_state);
7615728Sgblack@eecs.umich.edu        delete pkt->req;
7625728Sgblack@eecs.umich.edu        delete pkt;
7635728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
7645728Sgblack@eecs.umich.edu        delete send_state;
7655728Sgblack@eecs.umich.edu
7665728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
7675728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
7685728Sgblack@eecs.umich.edu        assert(main_send_state);
7695728Sgblack@eecs.umich.edu        // Record the fact that this packet is no longer outstanding.
7705728Sgblack@eecs.umich.edu        assert(main_send_state->outstanding != 0);
7715728Sgblack@eecs.umich.edu        main_send_state->outstanding--;
7725728Sgblack@eecs.umich.edu
7735728Sgblack@eecs.umich.edu        if (main_send_state->outstanding) {
7745728Sgblack@eecs.umich.edu            return;
7755728Sgblack@eecs.umich.edu        } else {
7765728Sgblack@eecs.umich.edu            delete main_send_state;
7775728Sgblack@eecs.umich.edu            big_pkt->senderState = NULL;
7785728Sgblack@eecs.umich.edu            pkt = big_pkt;
7795728Sgblack@eecs.umich.edu        }
7805728Sgblack@eecs.umich.edu    }
7815728Sgblack@eecs.umich.edu
7829342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
7835728Sgblack@eecs.umich.edu
7842623SN/A    Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
7852623SN/A
7864998Sgblack@eecs.umich.edu    // keep an instruction count
7874998Sgblack@eecs.umich.edu    if (fault == NoFault)
7884998Sgblack@eecs.umich.edu        countInst();
7895001Sgblack@eecs.umich.edu    else if (traceData) {
7905001Sgblack@eecs.umich.edu        // If there was a fault, we shouldn't trace this instruction.
7915001Sgblack@eecs.umich.edu        delete traceData;
7925001Sgblack@eecs.umich.edu        traceData = NULL;
7935001Sgblack@eecs.umich.edu    }
7944998Sgblack@eecs.umich.edu
7955507Sstever@gmail.com    // the locked flag may be cleared on the response packet, so check
7965507Sstever@gmail.com    // pkt->req and not pkt to see if it was a load-locked
7976102Sgblack@eecs.umich.edu    if (pkt->isRead() && pkt->req->isLLSC()) {
7983170Sstever@eecs.umich.edu        TheISA::handleLockedRead(thread, pkt->req);
7993170Sstever@eecs.umich.edu    }
8003170Sstever@eecs.umich.edu
8012644Sstever@eecs.umich.edu    delete pkt->req;
8022644Sstever@eecs.umich.edu    delete pkt;
8032644Sstever@eecs.umich.edu
8043184Srdreslin@umich.edu    postExecute();
8053227Sktlim@umich.edu
8062644Sstever@eecs.umich.edu    advanceInst(fault);
8072623SN/A}
8082623SN/A
80910030SAli.Saidi@ARM.comvoid
81010464SAndreas.Sandberg@ARM.comTimingSimpleCPU::updateCycleCounts()
81110464SAndreas.Sandberg@ARM.com{
81210464SAndreas.Sandberg@ARM.com    const Cycles delta(curCycle() - previousCycle);
81310464SAndreas.Sandberg@ARM.com
81410464SAndreas.Sandberg@ARM.com    numCycles += delta;
81510464SAndreas.Sandberg@ARM.com    ppCycles->notify(delta);
81610464SAndreas.Sandberg@ARM.com
81710464SAndreas.Sandberg@ARM.com    previousCycle = curCycle();
81810464SAndreas.Sandberg@ARM.com}
81910464SAndreas.Sandberg@ARM.com
82010464SAndreas.Sandberg@ARM.comvoid
82110030SAli.Saidi@ARM.comTimingSimpleCPU::DcachePort::recvTimingSnoopReq(PacketPtr pkt)
82210030SAli.Saidi@ARM.com{
82310529Smorr@cs.wisc.edu    // X86 ISA: Snooping an invalidation for monitor/mwait
82410529Smorr@cs.wisc.edu    if(cpu->getAddrMonitor()->doMonitor(pkt)) {
82510529Smorr@cs.wisc.edu        cpu->wakeup();
82610529Smorr@cs.wisc.edu    }
82710030SAli.Saidi@ARM.com    TheISA::handleLockedSnoop(cpu->thread, pkt, cacheBlockMask);
82810030SAli.Saidi@ARM.com}
82910030SAli.Saidi@ARM.com
83010529Smorr@cs.wisc.eduvoid
83110529Smorr@cs.wisc.eduTimingSimpleCPU::DcachePort::recvFunctionalSnoop(PacketPtr pkt)
83210529Smorr@cs.wisc.edu{
83310529Smorr@cs.wisc.edu    // X86 ISA: Snooping an invalidation for monitor/mwait
83410529Smorr@cs.wisc.edu    if(cpu->getAddrMonitor()->doMonitor(pkt)) {
83510529Smorr@cs.wisc.edu        cpu->wakeup();
83610529Smorr@cs.wisc.edu    }
83710529Smorr@cs.wisc.edu}
83810030SAli.Saidi@ARM.com
8392623SN/Abool
8408975Sandreas.hansson@arm.comTimingSimpleCPU::DcachePort::recvTimingResp(PacketPtr pkt)
8412623SN/A{
8429165Sandreas.hansson@arm.com    // delay processing of returned data until next CPU clock edge
8439648Sdam.sunwoo@arm.com    Tick next_tick = cpu->clockEdge();
8442948Ssaidi@eecs.umich.edu
8459165Sandreas.hansson@arm.com    if (next_tick == curTick()) {
8469165Sandreas.hansson@arm.com        cpu->completeDataAccess(pkt);
8479165Sandreas.hansson@arm.com    } else {
8489165Sandreas.hansson@arm.com        if (!tickEvent.scheduled()) {
8499165Sandreas.hansson@arm.com            tickEvent.schedule(pkt, next_tick);
8505728Sgblack@eecs.umich.edu        } else {
8519165Sandreas.hansson@arm.com            // In the case of a split transaction and a cache that is
8529165Sandreas.hansson@arm.com            // faster than a CPU we could get two responses before
8539165Sandreas.hansson@arm.com            // next_tick expires
8549165Sandreas.hansson@arm.com            if (!retryEvent.scheduled())
8559165Sandreas.hansson@arm.com                cpu->schedule(retryEvent, next_tick);
8569165Sandreas.hansson@arm.com            return false;
8574433Ssaidi@eecs.umich.edu        }
8583310Srdreslin@umich.edu    }
8598948Sandreas.hansson@arm.com
8604433Ssaidi@eecs.umich.edu    return true;
8612948Ssaidi@eecs.umich.edu}
8622948Ssaidi@eecs.umich.edu
8632948Ssaidi@eecs.umich.eduvoid
8642948Ssaidi@eecs.umich.eduTimingSimpleCPU::DcachePort::DTickEvent::process()
8652948Ssaidi@eecs.umich.edu{
8662630SN/A    cpu->completeDataAccess(pkt);
8672623SN/A}
8682623SN/A
8692657Ssaidi@eecs.umich.eduvoid
8702623SN/ATimingSimpleCPU::DcachePort::recvRetry()
8712623SN/A{
8722623SN/A    // we shouldn't get a retry unless we have a packet that we're
8732623SN/A    // waiting to transmit
8742623SN/A    assert(cpu->dcache_pkt != NULL);
8752623SN/A    assert(cpu->_status == DcacheRetry);
8763349Sbinkertn@umich.edu    PacketPtr tmp = cpu->dcache_pkt;
8775728Sgblack@eecs.umich.edu    if (tmp->senderState) {
8785728Sgblack@eecs.umich.edu        // This is a packet from a split access.
8795728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
8805728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(tmp->senderState);
8815728Sgblack@eecs.umich.edu        assert(send_state);
8825728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
8835728Sgblack@eecs.umich.edu
8845728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
8855728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
8865728Sgblack@eecs.umich.edu        assert(main_send_state);
8875728Sgblack@eecs.umich.edu
8888975Sandreas.hansson@arm.com        if (sendTimingReq(tmp)) {
8895728Sgblack@eecs.umich.edu            // If we were able to send without retrying, record that fact
8905728Sgblack@eecs.umich.edu            // and try sending the other fragment.
8915728Sgblack@eecs.umich.edu            send_state->clearFromParent();
8925728Sgblack@eecs.umich.edu            int other_index = main_send_state->getPendingFragment();
8935728Sgblack@eecs.umich.edu            if (other_index > 0) {
8945728Sgblack@eecs.umich.edu                tmp = main_send_state->fragments[other_index];
8955728Sgblack@eecs.umich.edu                cpu->dcache_pkt = tmp;
8965728Sgblack@eecs.umich.edu                if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) ||
8975728Sgblack@eecs.umich.edu                        (big_pkt->isWrite() && cpu->handleWritePacket())) {
8985728Sgblack@eecs.umich.edu                    main_send_state->fragments[other_index] = NULL;
8995728Sgblack@eecs.umich.edu                }
9005728Sgblack@eecs.umich.edu            } else {
9015728Sgblack@eecs.umich.edu                cpu->_status = DcacheWaitResponse;
9025728Sgblack@eecs.umich.edu                // memory system takes ownership of packet
9035728Sgblack@eecs.umich.edu                cpu->dcache_pkt = NULL;
9045728Sgblack@eecs.umich.edu            }
9055728Sgblack@eecs.umich.edu        }
9068975Sandreas.hansson@arm.com    } else if (sendTimingReq(tmp)) {
9072657Ssaidi@eecs.umich.edu        cpu->_status = DcacheWaitResponse;
9083170Sstever@eecs.umich.edu        // memory system takes ownership of packet
9092657Ssaidi@eecs.umich.edu        cpu->dcache_pkt = NULL;
9102657Ssaidi@eecs.umich.edu    }
9112623SN/A}
9122623SN/A
9135606Snate@binkert.orgTimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu,
9145606Snate@binkert.org    Tick t)
9155606Snate@binkert.org    : pkt(_pkt), cpu(_cpu)
9165103Ssaidi@eecs.umich.edu{
9175606Snate@binkert.org    cpu->schedule(this, t);
9185103Ssaidi@eecs.umich.edu}
9195103Ssaidi@eecs.umich.edu
9205103Ssaidi@eecs.umich.eduvoid
9215103Ssaidi@eecs.umich.eduTimingSimpleCPU::IprEvent::process()
9225103Ssaidi@eecs.umich.edu{
9235103Ssaidi@eecs.umich.edu    cpu->completeDataAccess(pkt);
9245103Ssaidi@eecs.umich.edu}
9255103Ssaidi@eecs.umich.edu
9265103Ssaidi@eecs.umich.educonst char *
9275336Shines@cs.fsu.eduTimingSimpleCPU::IprEvent::description() const
9285103Ssaidi@eecs.umich.edu{
9295103Ssaidi@eecs.umich.edu    return "Timing Simple CPU Delay IPR event";
9305103Ssaidi@eecs.umich.edu}
9315103Ssaidi@eecs.umich.edu
9322623SN/A
9335315Sstever@gmail.comvoid
9345315Sstever@gmail.comTimingSimpleCPU::printAddr(Addr a)
9355315Sstever@gmail.com{
9365315Sstever@gmail.com    dcachePort.printAddr(a);
9375315Sstever@gmail.com}
9385315Sstever@gmail.com
9395315Sstever@gmail.com
9402623SN/A////////////////////////////////////////////////////////////////////////
9412623SN/A//
9422623SN/A//  TimingSimpleCPU Simulation Object
9432623SN/A//
9444762Snate@binkert.orgTimingSimpleCPU *
9454762Snate@binkert.orgTimingSimpleCPUParams::create()
9462623SN/A{
9475529Snate@binkert.org    numThreads = 1;
9488779Sgblack@eecs.umich.edu    if (!FullSystem && workload.size() != 1)
9494762Snate@binkert.org        panic("only one workload allowed");
9505529Snate@binkert.org    return new TimingSimpleCPU(this);
9512623SN/A}
952