timing.cc revision 10030
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
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
729433SAndreas.Sandberg@ARM.com    if (FullSystem && !params()->switched_out) {
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),
919442SAndreas.Sandberg@ARM.com      fetchEvent(this), drainManager(NULL)
922623SN/A{
932623SN/A    _status = Idle;
943647Srdreslin@umich.edu
957897Shestness@cs.utexas.edu    system->totalNumInsts = 0;
962623SN/A}
972623SN/A
982623SN/A
9910030SAli.Saidi@ARM.com
1002623SN/ATimingSimpleCPU::~TimingSimpleCPU()
1012623SN/A{
1022623SN/A}
1032623SN/A
1042901Ssaidi@eecs.umich.eduunsigned int
1059342SAndreas.Sandberg@arm.comTimingSimpleCPU::drain(DrainManager *drain_manager)
1062798Sktlim@umich.edu{
1079448SAndreas.Sandberg@ARM.com    assert(!drainManager);
1089448SAndreas.Sandberg@ARM.com    if (switchedOut())
1099448SAndreas.Sandberg@ARM.com        return 0;
1109448SAndreas.Sandberg@ARM.com
1119342SAndreas.Sandberg@arm.com    if (_status == Idle ||
1129448SAndreas.Sandberg@ARM.com        (_status == BaseSimpleCPU::Running && isDrained())) {
1139442SAndreas.Sandberg@ARM.com        DPRINTF(Drain, "No need to drain.\n");
1142901Ssaidi@eecs.umich.edu        return 0;
1152798Sktlim@umich.edu    } else {
1169342SAndreas.Sandberg@arm.com        drainManager = drain_manager;
1179442SAndreas.Sandberg@ARM.com        DPRINTF(Drain, "Requesting drain: %s\n", pcState());
1189442SAndreas.Sandberg@ARM.com
1199442SAndreas.Sandberg@ARM.com        // The fetch event can become descheduled if a drain didn't
1209442SAndreas.Sandberg@ARM.com        // succeed on the first attempt. We need to reschedule it if
1219442SAndreas.Sandberg@ARM.com        // the CPU is waiting for a microcode routine to complete.
1229448SAndreas.Sandberg@ARM.com        if (_status == BaseSimpleCPU::Running && !fetchEvent.scheduled())
1239648Sdam.sunwoo@arm.com            schedule(fetchEvent, clockEdge());
1249442SAndreas.Sandberg@ARM.com
1252901Ssaidi@eecs.umich.edu        return 1;
1262798Sktlim@umich.edu    }
1272623SN/A}
1282623SN/A
1292623SN/Avoid
1309342SAndreas.Sandberg@arm.comTimingSimpleCPU::drainResume()
1312623SN/A{
1329442SAndreas.Sandberg@ARM.com    assert(!fetchEvent.scheduled());
1339448SAndreas.Sandberg@ARM.com    assert(!drainManager);
1349448SAndreas.Sandberg@ARM.com    if (switchedOut())
1359448SAndreas.Sandberg@ARM.com        return;
1369442SAndreas.Sandberg@ARM.com
1375221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Resume\n");
1389523SAndreas.Sandberg@ARM.com    verifyMemoryMode();
1393201Shsul@eecs.umich.edu
1409448SAndreas.Sandberg@ARM.com    assert(!threadContexts.empty());
1419448SAndreas.Sandberg@ARM.com    if (threadContexts.size() > 1)
1429448SAndreas.Sandberg@ARM.com        fatal("The timing CPU only supports one thread.\n");
1439448SAndreas.Sandberg@ARM.com
1449448SAndreas.Sandberg@ARM.com    if (thread->status() == ThreadContext::Active) {
1455710Scws3k@cs.virginia.edu        schedule(fetchEvent, nextCycle());
1469448SAndreas.Sandberg@ARM.com        _status = BaseSimpleCPU::Running;
1479837Slena@cs.wisc,edu        notIdleFraction = 1;
1489448SAndreas.Sandberg@ARM.com    } else {
1499448SAndreas.Sandberg@ARM.com        _status = BaseSimpleCPU::Idle;
1509837Slena@cs.wisc,edu        notIdleFraction = 0;
1512623SN/A    }
1529442SAndreas.Sandberg@ARM.com}
1532798Sktlim@umich.edu
1549442SAndreas.Sandberg@ARM.combool
1559442SAndreas.Sandberg@ARM.comTimingSimpleCPU::tryCompleteDrain()
1569442SAndreas.Sandberg@ARM.com{
1579442SAndreas.Sandberg@ARM.com    if (!drainManager)
1589442SAndreas.Sandberg@ARM.com        return false;
1599442SAndreas.Sandberg@ARM.com
1609442SAndreas.Sandberg@ARM.com    DPRINTF(Drain, "tryCompleteDrain: %s\n", pcState());
1619442SAndreas.Sandberg@ARM.com    if (!isDrained())
1629442SAndreas.Sandberg@ARM.com        return false;
1639442SAndreas.Sandberg@ARM.com
1649442SAndreas.Sandberg@ARM.com    DPRINTF(Drain, "CPU done draining, processing drain event\n");
1659442SAndreas.Sandberg@ARM.com    drainManager->signalDrainDone();
1669442SAndreas.Sandberg@ARM.com    drainManager = NULL;
1679442SAndreas.Sandberg@ARM.com
1689442SAndreas.Sandberg@ARM.com    return true;
1692798Sktlim@umich.edu}
1702798Sktlim@umich.edu
1712798Sktlim@umich.eduvoid
1722798Sktlim@umich.eduTimingSimpleCPU::switchOut()
1732798Sktlim@umich.edu{
1749429SAndreas.Sandberg@ARM.com    BaseSimpleCPU::switchOut();
1759429SAndreas.Sandberg@ARM.com
1769442SAndreas.Sandberg@ARM.com    assert(!fetchEvent.scheduled());
1779342SAndreas.Sandberg@arm.com    assert(_status == BaseSimpleCPU::Running || _status == Idle);
1789442SAndreas.Sandberg@ARM.com    assert(!stayAtPC);
1799442SAndreas.Sandberg@ARM.com    assert(microPC() == 0);
1809442SAndreas.Sandberg@ARM.com
1819179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
1822623SN/A}
1832623SN/A
1842623SN/A
1852623SN/Avoid
1862623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
1872623SN/A{
1889429SAndreas.Sandberg@ARM.com    BaseSimpleCPU::takeOverFrom(oldCPU);
1892623SN/A
1909179Sandreas.hansson@arm.com    previousCycle = curCycle();
1912623SN/A}
1922623SN/A
1939523SAndreas.Sandberg@ARM.comvoid
1949523SAndreas.Sandberg@ARM.comTimingSimpleCPU::verifyMemoryMode() const
1959523SAndreas.Sandberg@ARM.com{
1969524SAndreas.Sandberg@ARM.com    if (!system->isTimingMode()) {
1979523SAndreas.Sandberg@ARM.com        fatal("The timing CPU requires the memory system to be in "
1989523SAndreas.Sandberg@ARM.com              "'timing' mode.\n");
1999523SAndreas.Sandberg@ARM.com    }
2009523SAndreas.Sandberg@ARM.com}
2012623SN/A
2022623SN/Avoid
2039180Sandreas.hansson@arm.comTimingSimpleCPU::activateContext(ThreadID thread_num, Cycles delay)
2042623SN/A{
2055221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay);
2065221Ssaidi@eecs.umich.edu
2072623SN/A    assert(thread_num == 0);
2082683Sktlim@umich.edu    assert(thread);
2092623SN/A
2102623SN/A    assert(_status == Idle);
2112623SN/A
2129837Slena@cs.wisc,edu    notIdleFraction = 1;
2139342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
2143686Sktlim@umich.edu
2152623SN/A    // kick things off by initiating the fetch of the next instruction
2169179Sandreas.hansson@arm.com    schedule(fetchEvent, clockEdge(delay));
2172623SN/A}
2182623SN/A
2192623SN/A
2202623SN/Avoid
2218737Skoansin.tan@gmail.comTimingSimpleCPU::suspendContext(ThreadID thread_num)
2222623SN/A{
2235221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
2245221Ssaidi@eecs.umich.edu
2252623SN/A    assert(thread_num == 0);
2262683Sktlim@umich.edu    assert(thread);
2272623SN/A
2286043Sgblack@eecs.umich.edu    if (_status == Idle)
2296043Sgblack@eecs.umich.edu        return;
2306043Sgblack@eecs.umich.edu
2319342SAndreas.Sandberg@arm.com    assert(_status == BaseSimpleCPU::Running);
2322623SN/A
2332644Sstever@eecs.umich.edu    // just change status to Idle... if status != Running,
2342644Sstever@eecs.umich.edu    // completeInst() will not initiate fetch of next instruction.
2352623SN/A
2369837Slena@cs.wisc,edu    notIdleFraction = 0;
2372623SN/A    _status = Idle;
2382623SN/A}
2392623SN/A
2405728Sgblack@eecs.umich.edubool
2415728Sgblack@eecs.umich.eduTimingSimpleCPU::handleReadPacket(PacketPtr pkt)
2425728Sgblack@eecs.umich.edu{
2435728Sgblack@eecs.umich.edu    RequestPtr req = pkt->req;
2448105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
2459180Sandreas.hansson@arm.com        Cycles delay = TheISA::handleIprRead(thread->getTC(), pkt);
2469179Sandreas.hansson@arm.com        new IprEvent(pkt, this, clockEdge(delay));
2475728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2485728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2498975Sandreas.hansson@arm.com    } else if (!dcachePort.sendTimingReq(pkt)) {
2505728Sgblack@eecs.umich.edu        _status = DcacheRetry;
2515728Sgblack@eecs.umich.edu        dcache_pkt = pkt;
2525728Sgblack@eecs.umich.edu    } else {
2535728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
2545728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
2555728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
2565728Sgblack@eecs.umich.edu    }
2575728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
2585728Sgblack@eecs.umich.edu}
2592623SN/A
2605894Sgblack@eecs.umich.eduvoid
2616973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
2626973Stjones1@inf.ed.ac.uk                          bool read)
2635744Sgblack@eecs.umich.edu{
2645894Sgblack@eecs.umich.edu    PacketPtr pkt;
2655894Sgblack@eecs.umich.edu    buildPacket(pkt, req, read);
2667691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
2675894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
2685894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
2695894Sgblack@eecs.umich.edu        pkt->makeResponse();
2705894Sgblack@eecs.umich.edu        completeDataAccess(pkt);
2715894Sgblack@eecs.umich.edu    } else if (read) {
2725894Sgblack@eecs.umich.edu        handleReadPacket(pkt);
2735894Sgblack@eecs.umich.edu    } else {
2745894Sgblack@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
2755894Sgblack@eecs.umich.edu
2766102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
27710030SAli.Saidi@ARM.com            do_access = TheISA::handleLockedWrite(thread, req, dcachePort.cacheBlockMask);
2785894Sgblack@eecs.umich.edu        } else if (req->isCondSwap()) {
2795894Sgblack@eecs.umich.edu            assert(res);
2805894Sgblack@eecs.umich.edu            req->setExtraData(*res);
2815894Sgblack@eecs.umich.edu        }
2825894Sgblack@eecs.umich.edu
2835894Sgblack@eecs.umich.edu        if (do_access) {
2845894Sgblack@eecs.umich.edu            dcache_pkt = pkt;
2855894Sgblack@eecs.umich.edu            handleWritePacket();
2865894Sgblack@eecs.umich.edu        } else {
2875894Sgblack@eecs.umich.edu            _status = DcacheWaitResponse;
2885894Sgblack@eecs.umich.edu            completeDataAccess(pkt);
2895894Sgblack@eecs.umich.edu        }
2905894Sgblack@eecs.umich.edu    }
2915894Sgblack@eecs.umich.edu}
2925894Sgblack@eecs.umich.edu
2935894Sgblack@eecs.umich.eduvoid
2946973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendSplitData(RequestPtr req1, RequestPtr req2,
2956973Stjones1@inf.ed.ac.uk                               RequestPtr req, uint8_t *data, bool read)
2965894Sgblack@eecs.umich.edu{
2975894Sgblack@eecs.umich.edu    PacketPtr pkt1, pkt2;
2985894Sgblack@eecs.umich.edu    buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read);
2995894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3005894Sgblack@eecs.umich.edu        assert(!dcache_pkt);
3015894Sgblack@eecs.umich.edu        pkt1->makeResponse();
3025894Sgblack@eecs.umich.edu        completeDataAccess(pkt1);
3035894Sgblack@eecs.umich.edu    } else if (read) {
3047911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
3057911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3065894Sgblack@eecs.umich.edu        if (handleReadPacket(pkt1)) {
3075894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3087911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
3097911Shestness@cs.utexas.edu                    pkt2->senderState);
3105894Sgblack@eecs.umich.edu            if (handleReadPacket(pkt2)) {
3115894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3125894Sgblack@eecs.umich.edu            }
3135894Sgblack@eecs.umich.edu        }
3145894Sgblack@eecs.umich.edu    } else {
3155894Sgblack@eecs.umich.edu        dcache_pkt = pkt1;
3167911Shestness@cs.utexas.edu        SplitFragmentSenderState * send_state =
3177911Shestness@cs.utexas.edu            dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState);
3185894Sgblack@eecs.umich.edu        if (handleWritePacket()) {
3195894Sgblack@eecs.umich.edu            send_state->clearFromParent();
3205894Sgblack@eecs.umich.edu            dcache_pkt = pkt2;
3217911Shestness@cs.utexas.edu            send_state = dynamic_cast<SplitFragmentSenderState *>(
3227911Shestness@cs.utexas.edu                    pkt2->senderState);
3235894Sgblack@eecs.umich.edu            if (handleWritePacket()) {
3245894Sgblack@eecs.umich.edu                send_state->clearFromParent();
3255894Sgblack@eecs.umich.edu            }
3265894Sgblack@eecs.umich.edu        }
3275894Sgblack@eecs.umich.edu    }
3285894Sgblack@eecs.umich.edu}
3295894Sgblack@eecs.umich.edu
3305894Sgblack@eecs.umich.eduvoid
3315894Sgblack@eecs.umich.eduTimingSimpleCPU::translationFault(Fault fault)
3325894Sgblack@eecs.umich.edu{
3336739Sgblack@eecs.umich.edu    // fault may be NoFault in cases where a fault is suppressed,
3346739Sgblack@eecs.umich.edu    // for instance prefetches.
3359179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
3369179Sandreas.hansson@arm.com    previousCycle = curCycle();
3375894Sgblack@eecs.umich.edu
3385894Sgblack@eecs.umich.edu    if (traceData) {
3395894Sgblack@eecs.umich.edu        // Since there was a fault, we shouldn't trace this instruction.
3405894Sgblack@eecs.umich.edu        delete traceData;
3415894Sgblack@eecs.umich.edu        traceData = NULL;
3425744Sgblack@eecs.umich.edu    }
3435744Sgblack@eecs.umich.edu
3445894Sgblack@eecs.umich.edu    postExecute();
3455894Sgblack@eecs.umich.edu
3469442SAndreas.Sandberg@ARM.com    advanceInst(fault);
3475894Sgblack@eecs.umich.edu}
3485894Sgblack@eecs.umich.edu
3495894Sgblack@eecs.umich.eduvoid
3505894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
3515894Sgblack@eecs.umich.edu{
3525894Sgblack@eecs.umich.edu    MemCmd cmd;
3535894Sgblack@eecs.umich.edu    if (read) {
3545894Sgblack@eecs.umich.edu        cmd = MemCmd::ReadReq;
3556102Sgblack@eecs.umich.edu        if (req->isLLSC())
3565894Sgblack@eecs.umich.edu            cmd = MemCmd::LoadLockedReq;
3575894Sgblack@eecs.umich.edu    } else {
3585894Sgblack@eecs.umich.edu        cmd = MemCmd::WriteReq;
3596102Sgblack@eecs.umich.edu        if (req->isLLSC()) {
3605894Sgblack@eecs.umich.edu            cmd = MemCmd::StoreCondReq;
3615894Sgblack@eecs.umich.edu        } else if (req->isSwap()) {
3625894Sgblack@eecs.umich.edu            cmd = MemCmd::SwapReq;
3635894Sgblack@eecs.umich.edu        }
3645894Sgblack@eecs.umich.edu    }
3658949Sandreas.hansson@arm.com    pkt = new Packet(req, cmd);
3665894Sgblack@eecs.umich.edu}
3675894Sgblack@eecs.umich.edu
3685894Sgblack@eecs.umich.eduvoid
3695894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
3705894Sgblack@eecs.umich.edu        RequestPtr req1, RequestPtr req2, RequestPtr req,
3715894Sgblack@eecs.umich.edu        uint8_t *data, bool read)
3725894Sgblack@eecs.umich.edu{
3735894Sgblack@eecs.umich.edu    pkt1 = pkt2 = NULL;
3745894Sgblack@eecs.umich.edu
3758105Sgblack@eecs.umich.edu    assert(!req1->isMmappedIpr() && !req2->isMmappedIpr());
3765744Sgblack@eecs.umich.edu
3775894Sgblack@eecs.umich.edu    if (req->getFlags().isSet(Request::NO_ACCESS)) {
3785894Sgblack@eecs.umich.edu        buildPacket(pkt1, req, read);
3795894Sgblack@eecs.umich.edu        return;
3805894Sgblack@eecs.umich.edu    }
3815894Sgblack@eecs.umich.edu
3825894Sgblack@eecs.umich.edu    buildPacket(pkt1, req1, read);
3835894Sgblack@eecs.umich.edu    buildPacket(pkt2, req2, read);
3845894Sgblack@eecs.umich.edu
3858832SAli.Saidi@ARM.com    req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags(), dataMasterId());
3868949Sandreas.hansson@arm.com    PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand());
3875744Sgblack@eecs.umich.edu
3887691SAli.Saidi@ARM.com    pkt->dataDynamicArray<uint8_t>(data);
3895744Sgblack@eecs.umich.edu    pkt1->dataStatic<uint8_t>(data);
3905744Sgblack@eecs.umich.edu    pkt2->dataStatic<uint8_t>(data + req1->getSize());
3915744Sgblack@eecs.umich.edu
3925744Sgblack@eecs.umich.edu    SplitMainSenderState * main_send_state = new SplitMainSenderState;
3935744Sgblack@eecs.umich.edu    pkt->senderState = main_send_state;
3945744Sgblack@eecs.umich.edu    main_send_state->fragments[0] = pkt1;
3955744Sgblack@eecs.umich.edu    main_send_state->fragments[1] = pkt2;
3965744Sgblack@eecs.umich.edu    main_send_state->outstanding = 2;
3975744Sgblack@eecs.umich.edu    pkt1->senderState = new SplitFragmentSenderState(pkt, 0);
3985744Sgblack@eecs.umich.edu    pkt2->senderState = new SplitFragmentSenderState(pkt, 1);
3995744Sgblack@eecs.umich.edu}
4005744Sgblack@eecs.umich.edu
4012623SN/AFault
4028444Sgblack@eecs.umich.eduTimingSimpleCPU::readMem(Addr addr, uint8_t *data,
4038444Sgblack@eecs.umich.edu                         unsigned size, unsigned flags)
4042623SN/A{
4055728Sgblack@eecs.umich.edu    Fault fault;
4065728Sgblack@eecs.umich.edu    const int asid = 0;
4076221Snate@binkert.org    const ThreadID tid = 0;
4087720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4099814Sandreas.hansson@arm.com    unsigned block_size = cacheLineSize();
4106973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Read;
4112623SN/A
4127045Ssteve.reinhardt@amd.com    if (traceData) {
4137045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4147045Ssteve.reinhardt@amd.com    }
4157045Ssteve.reinhardt@amd.com
4167520Sgblack@eecs.umich.edu    RequestPtr req  = new Request(asid, addr, size,
4178832SAli.Saidi@ARM.com                                  flags, dataMasterId(), pc, _cpuId, tid);
4185728Sgblack@eecs.umich.edu
41910024Sdam.sunwoo@arm.com    req->taskId(taskId());
42010024Sdam.sunwoo@arm.com
4217520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4225744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4235728Sgblack@eecs.umich.edu
4245894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4255744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4265894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4276102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4285894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
4295894Sgblack@eecs.umich.edu
4306973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4317520Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, new uint8_t[size],
4326973Stjones1@inf.ed.ac.uk                                      NULL, mode);
4338486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
4348486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
4358486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
4368486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
4376973Stjones1@inf.ed.ac.uk
4386973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
4396973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
4405744Sgblack@eecs.umich.edu    } else {
4416973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
4427520Sgblack@eecs.umich.edu            new WholeTranslationState(req, new uint8_t[size], NULL, mode);
4438486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation
4448486Sgblack@eecs.umich.edu            = new DataTranslation<TimingSimpleCPU *>(this, state);
4456973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
4462623SN/A    }
4472623SN/A
4485728Sgblack@eecs.umich.edu    return NoFault;
4492623SN/A}
4502623SN/A
4515728Sgblack@eecs.umich.edubool
4525728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket()
4535728Sgblack@eecs.umich.edu{
4545728Sgblack@eecs.umich.edu    RequestPtr req = dcache_pkt->req;
4558105Sgblack@eecs.umich.edu    if (req->isMmappedIpr()) {
4569180Sandreas.hansson@arm.com        Cycles delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt);
4579179Sandreas.hansson@arm.com        new IprEvent(dcache_pkt, this, clockEdge(delay));
4585728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4595728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4608975Sandreas.hansson@arm.com    } else if (!dcachePort.sendTimingReq(dcache_pkt)) {
4615728Sgblack@eecs.umich.edu        _status = DcacheRetry;
4625728Sgblack@eecs.umich.edu    } else {
4635728Sgblack@eecs.umich.edu        _status = DcacheWaitResponse;
4645728Sgblack@eecs.umich.edu        // memory system takes ownership of packet
4655728Sgblack@eecs.umich.edu        dcache_pkt = NULL;
4665728Sgblack@eecs.umich.edu    }
4675728Sgblack@eecs.umich.edu    return dcache_pkt == NULL;
4685728Sgblack@eecs.umich.edu}
4692623SN/A
4702623SN/AFault
4718444Sgblack@eecs.umich.eduTimingSimpleCPU::writeMem(uint8_t *data, unsigned size,
4728444Sgblack@eecs.umich.edu                          Addr addr, unsigned flags, uint64_t *res)
4732623SN/A{
4748443Sgblack@eecs.umich.edu    uint8_t *newData = new uint8_t[size];
4758443Sgblack@eecs.umich.edu    memcpy(newData, data, size);
4768443Sgblack@eecs.umich.edu
4775728Sgblack@eecs.umich.edu    const int asid = 0;
4786221Snate@binkert.org    const ThreadID tid = 0;
4797720Sgblack@eecs.umich.edu    const Addr pc = thread->instAddr();
4809814Sandreas.hansson@arm.com    unsigned block_size = cacheLineSize();
4816973Stjones1@inf.ed.ac.uk    BaseTLB::Mode mode = BaseTLB::Write;
4823169Sstever@eecs.umich.edu
4837045Ssteve.reinhardt@amd.com    if (traceData) {
4847045Ssteve.reinhardt@amd.com        traceData->setAddr(addr);
4857045Ssteve.reinhardt@amd.com    }
4867045Ssteve.reinhardt@amd.com
4877520Sgblack@eecs.umich.edu    RequestPtr req = new Request(asid, addr, size,
4888832SAli.Saidi@ARM.com                                 flags, dataMasterId(), pc, _cpuId, tid);
4895728Sgblack@eecs.umich.edu
49010024Sdam.sunwoo@arm.com    req->taskId(taskId());
49110024Sdam.sunwoo@arm.com
4927520Sgblack@eecs.umich.edu    Addr split_addr = roundDown(addr + size - 1, block_size);
4935744Sgblack@eecs.umich.edu    assert(split_addr <= addr || split_addr - addr < block_size);
4945728Sgblack@eecs.umich.edu
4955894Sgblack@eecs.umich.edu    _status = DTBWaitResponse;
4965744Sgblack@eecs.umich.edu    if (split_addr > addr) {
4975894Sgblack@eecs.umich.edu        RequestPtr req1, req2;
4986102Sgblack@eecs.umich.edu        assert(!req->isLLSC() && !req->isSwap());
4995894Sgblack@eecs.umich.edu        req->splitOnVaddr(split_addr, req1, req2);
5005894Sgblack@eecs.umich.edu
5016973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
5028443Sgblack@eecs.umich.edu            new WholeTranslationState(req, req1, req2, newData, res, mode);
5038486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans1 =
5048486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 0);
5058486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *trans2 =
5068486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state, 1);
5076973Stjones1@inf.ed.ac.uk
5086973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req1, tc, trans1, mode);
5096973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req2, tc, trans2, mode);
5105744Sgblack@eecs.umich.edu    } else {
5116973Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
5128443Sgblack@eecs.umich.edu            new WholeTranslationState(req, newData, res, mode);
5138486Sgblack@eecs.umich.edu        DataTranslation<TimingSimpleCPU *> *translation =
5148486Sgblack@eecs.umich.edu            new DataTranslation<TimingSimpleCPU *>(this, state);
5156973Stjones1@inf.ed.ac.uk        thread->dtb->translateTiming(req, tc, translation, mode);
5162623SN/A    }
5172623SN/A
5187045Ssteve.reinhardt@amd.com    // Translation faults will be returned via finishTranslation()
5195728Sgblack@eecs.umich.edu    return NoFault;
5202623SN/A}
5212623SN/A
5222623SN/A
5232623SN/Avoid
5246973Stjones1@inf.ed.ac.ukTimingSimpleCPU::finishTranslation(WholeTranslationState *state)
5256973Stjones1@inf.ed.ac.uk{
5269342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
5276973Stjones1@inf.ed.ac.uk
5286973Stjones1@inf.ed.ac.uk    if (state->getFault() != NoFault) {
5296973Stjones1@inf.ed.ac.uk        if (state->isPrefetch()) {
5306973Stjones1@inf.ed.ac.uk            state->setNoFault();
5316973Stjones1@inf.ed.ac.uk        }
5327691SAli.Saidi@ARM.com        delete [] state->data;
5336973Stjones1@inf.ed.ac.uk        state->deleteReqs();
5346973Stjones1@inf.ed.ac.uk        translationFault(state->getFault());
5356973Stjones1@inf.ed.ac.uk    } else {
5366973Stjones1@inf.ed.ac.uk        if (!state->isSplit) {
5376973Stjones1@inf.ed.ac.uk            sendData(state->mainReq, state->data, state->res,
5386973Stjones1@inf.ed.ac.uk                     state->mode == BaseTLB::Read);
5396973Stjones1@inf.ed.ac.uk        } else {
5406973Stjones1@inf.ed.ac.uk            sendSplitData(state->sreqLow, state->sreqHigh, state->mainReq,
5416973Stjones1@inf.ed.ac.uk                          state->data, state->mode == BaseTLB::Read);
5426973Stjones1@inf.ed.ac.uk        }
5436973Stjones1@inf.ed.ac.uk    }
5446973Stjones1@inf.ed.ac.uk
5456973Stjones1@inf.ed.ac.uk    delete state;
5466973Stjones1@inf.ed.ac.uk}
5476973Stjones1@inf.ed.ac.uk
5486973Stjones1@inf.ed.ac.uk
5496973Stjones1@inf.ed.ac.ukvoid
5502623SN/ATimingSimpleCPU::fetch()
5512623SN/A{
5525221Ssaidi@eecs.umich.edu    DPRINTF(SimpleCPU, "Fetch\n");
5535221Ssaidi@eecs.umich.edu
5543387Sgblack@eecs.umich.edu    if (!curStaticInst || !curStaticInst->isDelayedCommit())
5553387Sgblack@eecs.umich.edu        checkForInterrupts();
5562631SN/A
5575348Ssaidi@eecs.umich.edu    checkPcEventQueue();
5585348Ssaidi@eecs.umich.edu
5598143SAli.Saidi@ARM.com    // We must have just got suspended by a PC event
5608143SAli.Saidi@ARM.com    if (_status == Idle)
5618143SAli.Saidi@ARM.com        return;
5628143SAli.Saidi@ARM.com
5637720Sgblack@eecs.umich.edu    TheISA::PCState pcState = thread->pcState();
5647720Sgblack@eecs.umich.edu    bool needToFetch = !isRomMicroPC(pcState.microPC()) && !curMacroStaticInst;
5652623SN/A
5667720Sgblack@eecs.umich.edu    if (needToFetch) {
5679342SAndreas.Sandberg@arm.com        _status = BaseSimpleCPU::Running;
5685669Sgblack@eecs.umich.edu        Request *ifetch_req = new Request();
56910024Sdam.sunwoo@arm.com        ifetch_req->taskId(taskId());
5705712Shsul@eecs.umich.edu        ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0);
5715894Sgblack@eecs.umich.edu        setupFetchRequest(ifetch_req);
5728277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translating address %#x\n", ifetch_req->getVaddr());
5736023Snate@binkert.org        thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation,
5746023Snate@binkert.org                BaseTLB::Execute);
5752623SN/A    } else {
5765669Sgblack@eecs.umich.edu        _status = IcacheWaitResponse;
5775669Sgblack@eecs.umich.edu        completeIfetch(NULL);
5785894Sgblack@eecs.umich.edu
5799179Sandreas.hansson@arm.com        numCycles += curCycle() - previousCycle;
5809179Sandreas.hansson@arm.com        previousCycle = curCycle();
5815894Sgblack@eecs.umich.edu    }
5825894Sgblack@eecs.umich.edu}
5835894Sgblack@eecs.umich.edu
5845894Sgblack@eecs.umich.edu
5855894Sgblack@eecs.umich.eduvoid
5865894Sgblack@eecs.umich.eduTimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc)
5875894Sgblack@eecs.umich.edu{
5885894Sgblack@eecs.umich.edu    if (fault == NoFault) {
5898277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Sending fetch for addr %#x(pa: %#x)\n",
5908277SAli.Saidi@ARM.com                req->getVaddr(), req->getPaddr());
5918949Sandreas.hansson@arm.com        ifetch_pkt = new Packet(req, MemCmd::ReadReq);
5925894Sgblack@eecs.umich.edu        ifetch_pkt->dataStatic(&inst);
5938277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, " -- pkt addr: %#x\n", ifetch_pkt->getAddr());
5945894Sgblack@eecs.umich.edu
5958975Sandreas.hansson@arm.com        if (!icachePort.sendTimingReq(ifetch_pkt)) {
5965894Sgblack@eecs.umich.edu            // Need to wait for retry
5975894Sgblack@eecs.umich.edu            _status = IcacheRetry;
5985894Sgblack@eecs.umich.edu        } else {
5995894Sgblack@eecs.umich.edu            // Need to wait for cache to respond
6005894Sgblack@eecs.umich.edu            _status = IcacheWaitResponse;
6015894Sgblack@eecs.umich.edu            // ownership of packet transferred to memory system
6025894Sgblack@eecs.umich.edu            ifetch_pkt = NULL;
6035894Sgblack@eecs.umich.edu        }
6045894Sgblack@eecs.umich.edu    } else {
6058277SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Translation of addr %#x faulted\n", req->getVaddr());
6065894Sgblack@eecs.umich.edu        delete req;
6075894Sgblack@eecs.umich.edu        // fetch fault: advance directly to next instruction (fault handler)
6089342SAndreas.Sandberg@arm.com        _status = BaseSimpleCPU::Running;
6095894Sgblack@eecs.umich.edu        advanceInst(fault);
6102623SN/A    }
6113222Sktlim@umich.edu
6129179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
6139179Sandreas.hansson@arm.com    previousCycle = curCycle();
6142623SN/A}
6152623SN/A
6162623SN/A
6172623SN/Avoid
6182644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault)
6192623SN/A{
6208276SAli.Saidi@ARM.com    if (_status == Faulting)
6218276SAli.Saidi@ARM.com        return;
6228276SAli.Saidi@ARM.com
6238276SAli.Saidi@ARM.com    if (fault != NoFault) {
6248276SAli.Saidi@ARM.com        advancePC(fault);
6258276SAli.Saidi@ARM.com        DPRINTF(SimpleCPU, "Fault occured, scheduling fetch event\n");
6269648Sdam.sunwoo@arm.com        reschedule(fetchEvent, clockEdge(), true);
6278276SAli.Saidi@ARM.com        _status = Faulting;
6288276SAli.Saidi@ARM.com        return;
6298276SAli.Saidi@ARM.com    }
6308276SAli.Saidi@ARM.com
6318276SAli.Saidi@ARM.com
6328276SAli.Saidi@ARM.com    if (!stayAtPC)
6335726Sgblack@eecs.umich.edu        advancePC(fault);
6342623SN/A
6359442SAndreas.Sandberg@ARM.com    if (tryCompleteDrain())
6369442SAndreas.Sandberg@ARM.com            return;
6379442SAndreas.Sandberg@ARM.com
6389342SAndreas.Sandberg@arm.com    if (_status == BaseSimpleCPU::Running) {
6392631SN/A        // kick off fetch of next instruction... callback from icache
6402631SN/A        // response will cause that instruction to be executed,
6412631SN/A        // keeping the CPU running.
6422631SN/A        fetch();
6432631SN/A    }
6442623SN/A}
6452623SN/A
6462623SN/A
6472623SN/Avoid
6483349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt)
6492623SN/A{
6508277SAli.Saidi@ARM.com    DPRINTF(SimpleCPU, "Complete ICache Fetch for addr %#x\n", pkt ?
6518277SAli.Saidi@ARM.com            pkt->getAddr() : 0);
6528277SAli.Saidi@ARM.com
6532623SN/A    // received a response from the icache: execute the received
6542623SN/A    // instruction
6555669Sgblack@eecs.umich.edu    assert(!pkt || !pkt->isError());
6562623SN/A    assert(_status == IcacheWaitResponse);
6572798Sktlim@umich.edu
6589342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
6592644Sstever@eecs.umich.edu
6609179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
6619179Sandreas.hansson@arm.com    previousCycle = curCycle();
6623222Sktlim@umich.edu
66310020Smatt.horsnell@ARM.com    if (pkt)
66410020Smatt.horsnell@ARM.com        pkt->req->setAccessLatency();
66510020Smatt.horsnell@ARM.com
66610020Smatt.horsnell@ARM.com
6672623SN/A    preExecute();
6687725SAli.Saidi@ARM.com    if (curStaticInst && curStaticInst->isMemRef()) {
6692623SN/A        // load or store: just send to dcache
6702623SN/A        Fault fault = curStaticInst->initiateAcc(this, traceData);
6717945SAli.Saidi@ARM.com
6727945SAli.Saidi@ARM.com        // If we're not running now the instruction will complete in a dcache
6737945SAli.Saidi@ARM.com        // response callback or the instruction faulted and has started an
6747945SAli.Saidi@ARM.com        // ifetch
6759342SAndreas.Sandberg@arm.com        if (_status == BaseSimpleCPU::Running) {
6765894Sgblack@eecs.umich.edu            if (fault != NoFault && traceData) {
6775001Sgblack@eecs.umich.edu                // If there was a fault, we shouldn't trace this instruction.
6785001Sgblack@eecs.umich.edu                delete traceData;
6795001Sgblack@eecs.umich.edu                traceData = NULL;
6803170Sstever@eecs.umich.edu            }
6814998Sgblack@eecs.umich.edu
6822644Sstever@eecs.umich.edu            postExecute();
6835103Ssaidi@eecs.umich.edu            // @todo remove me after debugging with legion done
6845103Ssaidi@eecs.umich.edu            if (curStaticInst && (!curStaticInst->isMicroop() ||
6855103Ssaidi@eecs.umich.edu                        curStaticInst->isFirstMicroop()))
6865103Ssaidi@eecs.umich.edu                instCnt++;
6872644Sstever@eecs.umich.edu            advanceInst(fault);
6882644Sstever@eecs.umich.edu        }
6895726Sgblack@eecs.umich.edu    } else if (curStaticInst) {
6902623SN/A        // non-memory instruction: execute completely now
6912623SN/A        Fault fault = curStaticInst->execute(this, traceData);
6924998Sgblack@eecs.umich.edu
6934998Sgblack@eecs.umich.edu        // keep an instruction count
6944998Sgblack@eecs.umich.edu        if (fault == NoFault)
6954998Sgblack@eecs.umich.edu            countInst();
6967655Sali.saidi@arm.com        else if (traceData && !DTRACE(ExecFaulting)) {
6975001Sgblack@eecs.umich.edu            delete traceData;
6985001Sgblack@eecs.umich.edu            traceData = NULL;
6995001Sgblack@eecs.umich.edu        }
7004998Sgblack@eecs.umich.edu
7012644Sstever@eecs.umich.edu        postExecute();
7025103Ssaidi@eecs.umich.edu        // @todo remove me after debugging with legion done
7035103Ssaidi@eecs.umich.edu        if (curStaticInst && (!curStaticInst->isMicroop() ||
7045103Ssaidi@eecs.umich.edu                    curStaticInst->isFirstMicroop()))
7055103Ssaidi@eecs.umich.edu            instCnt++;
7062644Sstever@eecs.umich.edu        advanceInst(fault);
7075726Sgblack@eecs.umich.edu    } else {
7085726Sgblack@eecs.umich.edu        advanceInst(NoFault);
7092623SN/A    }
7103658Sktlim@umich.edu
7115669Sgblack@eecs.umich.edu    if (pkt) {
7125669Sgblack@eecs.umich.edu        delete pkt->req;
7135669Sgblack@eecs.umich.edu        delete pkt;
7145669Sgblack@eecs.umich.edu    }
7152623SN/A}
7162623SN/A
7172948Ssaidi@eecs.umich.eduvoid
7182948Ssaidi@eecs.umich.eduTimingSimpleCPU::IcachePort::ITickEvent::process()
7192948Ssaidi@eecs.umich.edu{
7202948Ssaidi@eecs.umich.edu    cpu->completeIfetch(pkt);
7212948Ssaidi@eecs.umich.edu}
7222623SN/A
7232623SN/Abool
7248975Sandreas.hansson@arm.comTimingSimpleCPU::IcachePort::recvTimingResp(PacketPtr pkt)
7252623SN/A{
7269165Sandreas.hansson@arm.com    DPRINTF(SimpleCPU, "Received timing response %#x\n", pkt->getAddr());
7279165Sandreas.hansson@arm.com    // delay processing of returned data until next CPU clock edge
7289648Sdam.sunwoo@arm.com    Tick next_tick = cpu->clockEdge();
7292948Ssaidi@eecs.umich.edu
7309165Sandreas.hansson@arm.com    if (next_tick == curTick())
7319165Sandreas.hansson@arm.com        cpu->completeIfetch(pkt);
7329165Sandreas.hansson@arm.com    else
7339165Sandreas.hansson@arm.com        tickEvent.schedule(pkt, next_tick);
7348948Sandreas.hansson@arm.com
7354433Ssaidi@eecs.umich.edu    return true;
7362623SN/A}
7372623SN/A
7382657Ssaidi@eecs.umich.eduvoid
7392623SN/ATimingSimpleCPU::IcachePort::recvRetry()
7402623SN/A{
7412623SN/A    // we shouldn't get a retry unless we have a packet that we're
7422623SN/A    // waiting to transmit
7432623SN/A    assert(cpu->ifetch_pkt != NULL);
7442623SN/A    assert(cpu->_status == IcacheRetry);
7453349Sbinkertn@umich.edu    PacketPtr tmp = cpu->ifetch_pkt;
7468975Sandreas.hansson@arm.com    if (sendTimingReq(tmp)) {
7472657Ssaidi@eecs.umich.edu        cpu->_status = IcacheWaitResponse;
7482657Ssaidi@eecs.umich.edu        cpu->ifetch_pkt = NULL;
7492657Ssaidi@eecs.umich.edu    }
7502623SN/A}
7512623SN/A
7522623SN/Avoid
7533349Sbinkertn@umich.eduTimingSimpleCPU::completeDataAccess(PacketPtr pkt)
7542623SN/A{
7552623SN/A    // received a response from the dcache: complete the load or store
7562623SN/A    // instruction
7574870Sstever@eecs.umich.edu    assert(!pkt->isError());
7587516Shestness@cs.utexas.edu    assert(_status == DcacheWaitResponse || _status == DTBWaitResponse ||
7597516Shestness@cs.utexas.edu           pkt->req->getFlags().isSet(Request::NO_ACCESS));
7602623SN/A
76110020Smatt.horsnell@ARM.com    pkt->req->setAccessLatency();
7629179Sandreas.hansson@arm.com    numCycles += curCycle() - previousCycle;
7639179Sandreas.hansson@arm.com    previousCycle = curCycle();
7643184Srdreslin@umich.edu
7655728Sgblack@eecs.umich.edu    if (pkt->senderState) {
7665728Sgblack@eecs.umich.edu        SplitFragmentSenderState * send_state =
7675728Sgblack@eecs.umich.edu            dynamic_cast<SplitFragmentSenderState *>(pkt->senderState);
7685728Sgblack@eecs.umich.edu        assert(send_state);
7695728Sgblack@eecs.umich.edu        delete pkt->req;
7705728Sgblack@eecs.umich.edu        delete pkt;
7715728Sgblack@eecs.umich.edu        PacketPtr big_pkt = send_state->bigPkt;
7725728Sgblack@eecs.umich.edu        delete send_state;
7735728Sgblack@eecs.umich.edu
7745728Sgblack@eecs.umich.edu        SplitMainSenderState * main_send_state =
7755728Sgblack@eecs.umich.edu            dynamic_cast<SplitMainSenderState *>(big_pkt->senderState);
7765728Sgblack@eecs.umich.edu        assert(main_send_state);
7775728Sgblack@eecs.umich.edu        // Record the fact that this packet is no longer outstanding.
7785728Sgblack@eecs.umich.edu        assert(main_send_state->outstanding != 0);
7795728Sgblack@eecs.umich.edu        main_send_state->outstanding--;
7805728Sgblack@eecs.umich.edu
7815728Sgblack@eecs.umich.edu        if (main_send_state->outstanding) {
7825728Sgblack@eecs.umich.edu            return;
7835728Sgblack@eecs.umich.edu        } else {
7845728Sgblack@eecs.umich.edu            delete main_send_state;
7855728Sgblack@eecs.umich.edu            big_pkt->senderState = NULL;
7865728Sgblack@eecs.umich.edu            pkt = big_pkt;
7875728Sgblack@eecs.umich.edu        }
7885728Sgblack@eecs.umich.edu    }
7895728Sgblack@eecs.umich.edu
7909342SAndreas.Sandberg@arm.com    _status = BaseSimpleCPU::Running;
7915728Sgblack@eecs.umich.edu
7922623SN/A    Fault fault = curStaticInst->completeAcc(pkt, this, traceData);
7932623SN/A
7944998Sgblack@eecs.umich.edu    // keep an instruction count
7954998Sgblack@eecs.umich.edu    if (fault == NoFault)
7964998Sgblack@eecs.umich.edu        countInst();
7975001Sgblack@eecs.umich.edu    else if (traceData) {
7985001Sgblack@eecs.umich.edu        // If there was a fault, we shouldn't trace this instruction.
7995001Sgblack@eecs.umich.edu        delete traceData;
8005001Sgblack@eecs.umich.edu        traceData = NULL;
8015001Sgblack@eecs.umich.edu    }
8024998Sgblack@eecs.umich.edu
8035507Sstever@gmail.com    // the locked flag may be cleared on the response packet, so check
8045507Sstever@gmail.com    // pkt->req and not pkt to see if it was a load-locked
8056102Sgblack@eecs.umich.edu    if (pkt->isRead() && pkt->req->isLLSC()) {
8063170Sstever@eecs.umich.edu        TheISA::handleLockedRead(thread, pkt->req);
8073170Sstever@eecs.umich.edu    }
8083170Sstever@eecs.umich.edu
8092644Sstever@eecs.umich.edu    delete pkt->req;
8102644Sstever@eecs.umich.edu    delete pkt;
8112644Sstever@eecs.umich.edu
8123184Srdreslin@umich.edu    postExecute();
8133227Sktlim@umich.edu
8142644Sstever@eecs.umich.edu    advanceInst(fault);
8152623SN/A}
8162623SN/A
81710030SAli.Saidi@ARM.comvoid
81810030SAli.Saidi@ARM.comTimingSimpleCPU::DcachePort::recvTimingSnoopReq(PacketPtr pkt)
81910030SAli.Saidi@ARM.com{
82010030SAli.Saidi@ARM.com    TheISA::handleLockedSnoop(cpu->thread, pkt, cacheBlockMask);
82110030SAli.Saidi@ARM.com}
82210030SAli.Saidi@ARM.com
82310030SAli.Saidi@ARM.com
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
8289648Sdam.sunwoo@arm.com    Tick next_tick = cpu->clockEdge();
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