timing.cc revision 9424
12623SN/A/* 28948Sandreas.hansson@arm.com * Copyright (c) 2010-2012 ARM Limited 37725SAli.Saidi@ARM.com * All rights reserved 47725SAli.Saidi@ARM.com * 57725SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 67725SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 77725SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 87725SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 97725SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 107725SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 117725SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 127725SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 137725SAli.Saidi@ARM.com * 142623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 152623SN/A * All rights reserved. 162623SN/A * 172623SN/A * Redistribution and use in source and binary forms, with or without 182623SN/A * modification, are permitted provided that the following conditions are 192623SN/A * met: redistributions of source code must retain the above copyright 202623SN/A * notice, this list of conditions and the following disclaimer; 212623SN/A * redistributions in binary form must reproduce the above copyright 222623SN/A * notice, this list of conditions and the following disclaimer in the 232623SN/A * documentation and/or other materials provided with the distribution; 242623SN/A * neither the name of the copyright holders nor the names of its 252623SN/A * contributors may be used to endorse or promote products derived from 262623SN/A * this software without specific prior written permission. 272623SN/A * 282623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 412623SN/A */ 422623SN/A 433170Sstever@eecs.umich.edu#include "arch/locked_mem.hh" 448105Sgblack@eecs.umich.edu#include "arch/mmapped_ipr.hh" 452623SN/A#include "arch/utility.hh" 464040Ssaidi@eecs.umich.edu#include "base/bigint.hh" 476658Snate@binkert.org#include "config/the_isa.hh" 488229Snate@binkert.org#include "cpu/simple/timing.hh" 492623SN/A#include "cpu/exetrace.hh" 508232Snate@binkert.org#include "debug/Config.hh" 519152Satgutier@umich.edu#include "debug/Drain.hh" 528232Snate@binkert.org#include "debug/ExecFaulting.hh" 538232Snate@binkert.org#include "debug/SimpleCPU.hh" 543348Sbinkertn@umich.edu#include "mem/packet.hh" 553348Sbinkertn@umich.edu#include "mem/packet_access.hh" 564762Snate@binkert.org#include "params/TimingSimpleCPU.hh" 577678Sgblack@eecs.umich.edu#include "sim/faults.hh" 588779Sgblack@eecs.umich.edu#include "sim/full_system.hh" 592901Ssaidi@eecs.umich.edu#include "sim/system.hh" 602623SN/A 612623SN/Ausing namespace std; 622623SN/Ausing namespace TheISA; 632623SN/A 642623SN/Avoid 652623SN/ATimingSimpleCPU::init() 662623SN/A{ 672623SN/A BaseCPU::init(); 688921Sandreas.hansson@arm.com 699424SAndreas.Sandberg@ARM.com if (!params()->defer_registration && 709424SAndreas.Sandberg@ARM.com system->getMemoryMode() != Enums::timing) { 719424SAndreas.Sandberg@ARM.com fatal("The timing CPU requires the memory system to be in " 729424SAndreas.Sandberg@ARM.com "'timing' mode.\n"); 739424SAndreas.Sandberg@ARM.com } 749424SAndreas.Sandberg@ARM.com 758921Sandreas.hansson@arm.com // Initialise the ThreadContext's memory proxies 768921Sandreas.hansson@arm.com tcBase()->initMemProxies(tcBase()); 778921Sandreas.hansson@arm.com 789058Satgutier@umich.edu if (FullSystem && !params()->defer_registration) { 798779Sgblack@eecs.umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 808779Sgblack@eecs.umich.edu ThreadContext *tc = threadContexts[i]; 818779Sgblack@eecs.umich.edu // initialize CPU, including PC 828779Sgblack@eecs.umich.edu TheISA::initCPU(tc, _cpuId); 838779Sgblack@eecs.umich.edu } 842623SN/A } 852623SN/A} 862623SN/A 872623SN/Avoid 888707Sandreas.hansson@arm.comTimingSimpleCPU::TimingCPUPort::TickEvent::schedule(PacketPtr _pkt, Tick t) 892948Ssaidi@eecs.umich.edu{ 902948Ssaidi@eecs.umich.edu pkt = _pkt; 915606Snate@binkert.org cpu->schedule(this, t); 922948Ssaidi@eecs.umich.edu} 932948Ssaidi@eecs.umich.edu 945529Snate@binkert.orgTimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p) 958707Sandreas.hansson@arm.com : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this), 969179Sandreas.hansson@arm.com dcachePort(this), ifetch_pkt(NULL), dcache_pkt(NULL), previousCycle(0), 979179Sandreas.hansson@arm.com fetchEvent(this) 982623SN/A{ 992623SN/A _status = Idle; 1003647Srdreslin@umich.edu 1019342SAndreas.Sandberg@arm.com setDrainState(Drainable::Running); 1027897Shestness@cs.utexas.edu system->totalNumInsts = 0; 1032623SN/A} 1042623SN/A 1052623SN/A 1062623SN/ATimingSimpleCPU::~TimingSimpleCPU() 1072623SN/A{ 1082623SN/A} 1092623SN/A 1102623SN/Avoid 1112623SN/ATimingSimpleCPU::serialize(ostream &os) 1122623SN/A{ 1139342SAndreas.Sandberg@arm.com Drainable::State so_state(getDrainState()); 1142915Sktlim@umich.edu SERIALIZE_ENUM(so_state); 1152623SN/A BaseSimpleCPU::serialize(os); 1162623SN/A} 1172623SN/A 1182623SN/Avoid 1192623SN/ATimingSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 1202623SN/A{ 1219342SAndreas.Sandberg@arm.com Drainable::State so_state; 1222915Sktlim@umich.edu UNSERIALIZE_ENUM(so_state); 1232623SN/A BaseSimpleCPU::unserialize(cp, section); 1242798Sktlim@umich.edu} 1252798Sktlim@umich.edu 1262901Ssaidi@eecs.umich.eduunsigned int 1279342SAndreas.Sandberg@arm.comTimingSimpleCPU::drain(DrainManager *drain_manager) 1282798Sktlim@umich.edu{ 1292839Sktlim@umich.edu // TimingSimpleCPU is ready to drain if it's not waiting for 1302798Sktlim@umich.edu // an access to complete. 1319342SAndreas.Sandberg@arm.com if (_status == Idle || 1329342SAndreas.Sandberg@arm.com _status == BaseSimpleCPU::Running || 1339342SAndreas.Sandberg@arm.com _status == SwitchedOut) { 1349342SAndreas.Sandberg@arm.com setDrainState(Drainable::Drained); 1352901Ssaidi@eecs.umich.edu return 0; 1362798Sktlim@umich.edu } else { 1379342SAndreas.Sandberg@arm.com setDrainState(Drainable::Draining); 1389342SAndreas.Sandberg@arm.com drainManager = drain_manager; 1399152Satgutier@umich.edu DPRINTF(Drain, "CPU not drained\n"); 1402901Ssaidi@eecs.umich.edu return 1; 1412798Sktlim@umich.edu } 1422623SN/A} 1432623SN/A 1442623SN/Avoid 1459342SAndreas.Sandberg@arm.comTimingSimpleCPU::drainResume() 1462623SN/A{ 1475221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "Resume\n"); 1482798Sktlim@umich.edu if (_status != SwitchedOut && _status != Idle) { 1499424SAndreas.Sandberg@ARM.com if (system->getMemoryMode() != Enums::timing) { 1509424SAndreas.Sandberg@ARM.com fatal("The timing CPU requires the memory system to be in " 1519424SAndreas.Sandberg@ARM.com "'timing' mode.\n"); 1529424SAndreas.Sandberg@ARM.com } 1533201Shsul@eecs.umich.edu 1545710Scws3k@cs.virginia.edu if (fetchEvent.scheduled()) 1555710Scws3k@cs.virginia.edu deschedule(fetchEvent); 1562915Sktlim@umich.edu 1575710Scws3k@cs.virginia.edu schedule(fetchEvent, nextCycle()); 1582623SN/A } 1592798Sktlim@umich.edu 1609342SAndreas.Sandberg@arm.com setDrainState(Drainable::Running); 1612798Sktlim@umich.edu} 1622798Sktlim@umich.edu 1632798Sktlim@umich.eduvoid 1642798Sktlim@umich.eduTimingSimpleCPU::switchOut() 1652798Sktlim@umich.edu{ 1669342SAndreas.Sandberg@arm.com assert(_status == BaseSimpleCPU::Running || _status == Idle); 1672798Sktlim@umich.edu _status = SwitchedOut; 1689179Sandreas.hansson@arm.com numCycles += curCycle() - previousCycle; 1692867Sktlim@umich.edu 1702867Sktlim@umich.edu // If we've been scheduled to resume but are then told to switch out, 1712867Sktlim@umich.edu // we'll need to cancel it. 1725710Scws3k@cs.virginia.edu if (fetchEvent.scheduled()) 1735606Snate@binkert.org deschedule(fetchEvent); 1742623SN/A} 1752623SN/A 1762623SN/A 1772623SN/Avoid 1782623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 1792623SN/A{ 1808737Skoansin.tan@gmail.com BaseCPU::takeOverFrom(oldCPU); 1812623SN/A 1822680Sktlim@umich.edu // if any of this CPU's ThreadContexts are active, mark the CPU as 1832623SN/A // running and schedule its tick event. 1842680Sktlim@umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 1852680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 1869342SAndreas.Sandberg@arm.com if (tc->status() == ThreadContext::Active && 1879342SAndreas.Sandberg@arm.com _status != BaseSimpleCPU::Running) { 1889342SAndreas.Sandberg@arm.com _status = BaseSimpleCPU::Running; 1892623SN/A break; 1902623SN/A } 1912623SN/A } 1923201Shsul@eecs.umich.edu 1939342SAndreas.Sandberg@arm.com if (_status != BaseSimpleCPU::Running) { 1943201Shsul@eecs.umich.edu _status = Idle; 1953201Shsul@eecs.umich.edu } 1965169Ssaidi@eecs.umich.edu assert(threadContexts.size() == 1); 1979179Sandreas.hansson@arm.com previousCycle = curCycle(); 1982623SN/A} 1992623SN/A 2002623SN/A 2012623SN/Avoid 2029180Sandreas.hansson@arm.comTimingSimpleCPU::activateContext(ThreadID thread_num, Cycles delay) 2032623SN/A{ 2045221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay); 2055221Ssaidi@eecs.umich.edu 2062623SN/A assert(thread_num == 0); 2072683Sktlim@umich.edu assert(thread); 2082623SN/A 2092623SN/A assert(_status == Idle); 2102623SN/A 2112623SN/A notIdleFraction++; 2129342SAndreas.Sandberg@arm.com _status = BaseSimpleCPU::Running; 2133686Sktlim@umich.edu 2142623SN/A // kick things off by initiating the fetch of the next instruction 2159179Sandreas.hansson@arm.com schedule(fetchEvent, clockEdge(delay)); 2162623SN/A} 2172623SN/A 2182623SN/A 2192623SN/Avoid 2208737Skoansin.tan@gmail.comTimingSimpleCPU::suspendContext(ThreadID thread_num) 2212623SN/A{ 2225221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num); 2235221Ssaidi@eecs.umich.edu 2242623SN/A assert(thread_num == 0); 2252683Sktlim@umich.edu assert(thread); 2262623SN/A 2276043Sgblack@eecs.umich.edu if (_status == Idle) 2286043Sgblack@eecs.umich.edu return; 2296043Sgblack@eecs.umich.edu 2309342SAndreas.Sandberg@arm.com assert(_status == BaseSimpleCPU::Running); 2312623SN/A 2322644Sstever@eecs.umich.edu // just change status to Idle... if status != Running, 2332644Sstever@eecs.umich.edu // completeInst() will not initiate fetch of next instruction. 2342623SN/A 2352623SN/A notIdleFraction--; 2362623SN/A _status = Idle; 2372623SN/A} 2382623SN/A 2395728Sgblack@eecs.umich.edubool 2405728Sgblack@eecs.umich.eduTimingSimpleCPU::handleReadPacket(PacketPtr pkt) 2415728Sgblack@eecs.umich.edu{ 2425728Sgblack@eecs.umich.edu RequestPtr req = pkt->req; 2438105Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 2449180Sandreas.hansson@arm.com Cycles delay = TheISA::handleIprRead(thread->getTC(), pkt); 2459179Sandreas.hansson@arm.com new IprEvent(pkt, this, clockEdge(delay)); 2465728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 2475728Sgblack@eecs.umich.edu dcache_pkt = NULL; 2488975Sandreas.hansson@arm.com } else if (!dcachePort.sendTimingReq(pkt)) { 2495728Sgblack@eecs.umich.edu _status = DcacheRetry; 2505728Sgblack@eecs.umich.edu dcache_pkt = pkt; 2515728Sgblack@eecs.umich.edu } else { 2525728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 2535728Sgblack@eecs.umich.edu // memory system takes ownership of packet 2545728Sgblack@eecs.umich.edu dcache_pkt = NULL; 2555728Sgblack@eecs.umich.edu } 2565728Sgblack@eecs.umich.edu return dcache_pkt == NULL; 2575728Sgblack@eecs.umich.edu} 2582623SN/A 2595894Sgblack@eecs.umich.eduvoid 2606973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res, 2616973Stjones1@inf.ed.ac.uk bool read) 2625744Sgblack@eecs.umich.edu{ 2635894Sgblack@eecs.umich.edu PacketPtr pkt; 2645894Sgblack@eecs.umich.edu buildPacket(pkt, req, read); 2657691SAli.Saidi@ARM.com pkt->dataDynamicArray<uint8_t>(data); 2665894Sgblack@eecs.umich.edu if (req->getFlags().isSet(Request::NO_ACCESS)) { 2675894Sgblack@eecs.umich.edu assert(!dcache_pkt); 2685894Sgblack@eecs.umich.edu pkt->makeResponse(); 2695894Sgblack@eecs.umich.edu completeDataAccess(pkt); 2705894Sgblack@eecs.umich.edu } else if (read) { 2715894Sgblack@eecs.umich.edu handleReadPacket(pkt); 2725894Sgblack@eecs.umich.edu } else { 2735894Sgblack@eecs.umich.edu bool do_access = true; // flag to suppress cache access 2745894Sgblack@eecs.umich.edu 2756102Sgblack@eecs.umich.edu if (req->isLLSC()) { 2765894Sgblack@eecs.umich.edu do_access = TheISA::handleLockedWrite(thread, req); 2775894Sgblack@eecs.umich.edu } else if (req->isCondSwap()) { 2785894Sgblack@eecs.umich.edu assert(res); 2795894Sgblack@eecs.umich.edu req->setExtraData(*res); 2805894Sgblack@eecs.umich.edu } 2815894Sgblack@eecs.umich.edu 2825894Sgblack@eecs.umich.edu if (do_access) { 2835894Sgblack@eecs.umich.edu dcache_pkt = pkt; 2845894Sgblack@eecs.umich.edu handleWritePacket(); 2855894Sgblack@eecs.umich.edu } else { 2865894Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 2875894Sgblack@eecs.umich.edu completeDataAccess(pkt); 2885894Sgblack@eecs.umich.edu } 2895894Sgblack@eecs.umich.edu } 2905894Sgblack@eecs.umich.edu} 2915894Sgblack@eecs.umich.edu 2925894Sgblack@eecs.umich.eduvoid 2936973Stjones1@inf.ed.ac.ukTimingSimpleCPU::sendSplitData(RequestPtr req1, RequestPtr req2, 2946973Stjones1@inf.ed.ac.uk RequestPtr req, uint8_t *data, bool read) 2955894Sgblack@eecs.umich.edu{ 2965894Sgblack@eecs.umich.edu PacketPtr pkt1, pkt2; 2975894Sgblack@eecs.umich.edu buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read); 2985894Sgblack@eecs.umich.edu if (req->getFlags().isSet(Request::NO_ACCESS)) { 2995894Sgblack@eecs.umich.edu assert(!dcache_pkt); 3005894Sgblack@eecs.umich.edu pkt1->makeResponse(); 3015894Sgblack@eecs.umich.edu completeDataAccess(pkt1); 3025894Sgblack@eecs.umich.edu } else if (read) { 3037911Shestness@cs.utexas.edu SplitFragmentSenderState * send_state = 3047911Shestness@cs.utexas.edu dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState); 3055894Sgblack@eecs.umich.edu if (handleReadPacket(pkt1)) { 3065894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3077911Shestness@cs.utexas.edu send_state = dynamic_cast<SplitFragmentSenderState *>( 3087911Shestness@cs.utexas.edu pkt2->senderState); 3095894Sgblack@eecs.umich.edu if (handleReadPacket(pkt2)) { 3105894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3115894Sgblack@eecs.umich.edu } 3125894Sgblack@eecs.umich.edu } 3135894Sgblack@eecs.umich.edu } else { 3145894Sgblack@eecs.umich.edu dcache_pkt = pkt1; 3157911Shestness@cs.utexas.edu SplitFragmentSenderState * send_state = 3167911Shestness@cs.utexas.edu dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState); 3175894Sgblack@eecs.umich.edu if (handleWritePacket()) { 3185894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3195894Sgblack@eecs.umich.edu dcache_pkt = pkt2; 3207911Shestness@cs.utexas.edu send_state = dynamic_cast<SplitFragmentSenderState *>( 3217911Shestness@cs.utexas.edu pkt2->senderState); 3225894Sgblack@eecs.umich.edu if (handleWritePacket()) { 3235894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3245894Sgblack@eecs.umich.edu } 3255894Sgblack@eecs.umich.edu } 3265894Sgblack@eecs.umich.edu } 3275894Sgblack@eecs.umich.edu} 3285894Sgblack@eecs.umich.edu 3295894Sgblack@eecs.umich.eduvoid 3305894Sgblack@eecs.umich.eduTimingSimpleCPU::translationFault(Fault fault) 3315894Sgblack@eecs.umich.edu{ 3326739Sgblack@eecs.umich.edu // fault may be NoFault in cases where a fault is suppressed, 3336739Sgblack@eecs.umich.edu // for instance prefetches. 3349179Sandreas.hansson@arm.com numCycles += curCycle() - previousCycle; 3359179Sandreas.hansson@arm.com previousCycle = curCycle(); 3365894Sgblack@eecs.umich.edu 3375894Sgblack@eecs.umich.edu if (traceData) { 3385894Sgblack@eecs.umich.edu // Since there was a fault, we shouldn't trace this instruction. 3395894Sgblack@eecs.umich.edu delete traceData; 3405894Sgblack@eecs.umich.edu traceData = NULL; 3415744Sgblack@eecs.umich.edu } 3425744Sgblack@eecs.umich.edu 3435894Sgblack@eecs.umich.edu postExecute(); 3445894Sgblack@eecs.umich.edu 3459342SAndreas.Sandberg@arm.com if (getDrainState() == Drainable::Draining) { 3465894Sgblack@eecs.umich.edu advancePC(fault); 3475894Sgblack@eecs.umich.edu completeDrain(); 3485894Sgblack@eecs.umich.edu } else { 3495894Sgblack@eecs.umich.edu advanceInst(fault); 3505894Sgblack@eecs.umich.edu } 3515894Sgblack@eecs.umich.edu} 3525894Sgblack@eecs.umich.edu 3535894Sgblack@eecs.umich.eduvoid 3545894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read) 3555894Sgblack@eecs.umich.edu{ 3565894Sgblack@eecs.umich.edu MemCmd cmd; 3575894Sgblack@eecs.umich.edu if (read) { 3585894Sgblack@eecs.umich.edu cmd = MemCmd::ReadReq; 3596102Sgblack@eecs.umich.edu if (req->isLLSC()) 3605894Sgblack@eecs.umich.edu cmd = MemCmd::LoadLockedReq; 3615894Sgblack@eecs.umich.edu } else { 3625894Sgblack@eecs.umich.edu cmd = MemCmd::WriteReq; 3636102Sgblack@eecs.umich.edu if (req->isLLSC()) { 3645894Sgblack@eecs.umich.edu cmd = MemCmd::StoreCondReq; 3655894Sgblack@eecs.umich.edu } else if (req->isSwap()) { 3665894Sgblack@eecs.umich.edu cmd = MemCmd::SwapReq; 3675894Sgblack@eecs.umich.edu } 3685894Sgblack@eecs.umich.edu } 3698949Sandreas.hansson@arm.com pkt = new Packet(req, cmd); 3705894Sgblack@eecs.umich.edu} 3715894Sgblack@eecs.umich.edu 3725894Sgblack@eecs.umich.eduvoid 3735894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, 3745894Sgblack@eecs.umich.edu RequestPtr req1, RequestPtr req2, RequestPtr req, 3755894Sgblack@eecs.umich.edu uint8_t *data, bool read) 3765894Sgblack@eecs.umich.edu{ 3775894Sgblack@eecs.umich.edu pkt1 = pkt2 = NULL; 3785894Sgblack@eecs.umich.edu 3798105Sgblack@eecs.umich.edu assert(!req1->isMmappedIpr() && !req2->isMmappedIpr()); 3805744Sgblack@eecs.umich.edu 3815894Sgblack@eecs.umich.edu if (req->getFlags().isSet(Request::NO_ACCESS)) { 3825894Sgblack@eecs.umich.edu buildPacket(pkt1, req, read); 3835894Sgblack@eecs.umich.edu return; 3845894Sgblack@eecs.umich.edu } 3855894Sgblack@eecs.umich.edu 3865894Sgblack@eecs.umich.edu buildPacket(pkt1, req1, read); 3875894Sgblack@eecs.umich.edu buildPacket(pkt2, req2, read); 3885894Sgblack@eecs.umich.edu 3898832SAli.Saidi@ARM.com req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags(), dataMasterId()); 3908949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand()); 3915744Sgblack@eecs.umich.edu 3927691SAli.Saidi@ARM.com pkt->dataDynamicArray<uint8_t>(data); 3935744Sgblack@eecs.umich.edu pkt1->dataStatic<uint8_t>(data); 3945744Sgblack@eecs.umich.edu pkt2->dataStatic<uint8_t>(data + req1->getSize()); 3955744Sgblack@eecs.umich.edu 3965744Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = new SplitMainSenderState; 3975744Sgblack@eecs.umich.edu pkt->senderState = main_send_state; 3985744Sgblack@eecs.umich.edu main_send_state->fragments[0] = pkt1; 3995744Sgblack@eecs.umich.edu main_send_state->fragments[1] = pkt2; 4005744Sgblack@eecs.umich.edu main_send_state->outstanding = 2; 4015744Sgblack@eecs.umich.edu pkt1->senderState = new SplitFragmentSenderState(pkt, 0); 4025744Sgblack@eecs.umich.edu pkt2->senderState = new SplitFragmentSenderState(pkt, 1); 4035744Sgblack@eecs.umich.edu} 4045744Sgblack@eecs.umich.edu 4052623SN/AFault 4068444Sgblack@eecs.umich.eduTimingSimpleCPU::readMem(Addr addr, uint8_t *data, 4078444Sgblack@eecs.umich.edu unsigned size, unsigned flags) 4082623SN/A{ 4095728Sgblack@eecs.umich.edu Fault fault; 4105728Sgblack@eecs.umich.edu const int asid = 0; 4116221Snate@binkert.org const ThreadID tid = 0; 4127720Sgblack@eecs.umich.edu const Addr pc = thread->instAddr(); 4136227Snate@binkert.org unsigned block_size = dcachePort.peerBlockSize(); 4146973Stjones1@inf.ed.ac.uk BaseTLB::Mode mode = BaseTLB::Read; 4152623SN/A 4167045Ssteve.reinhardt@amd.com if (traceData) { 4177045Ssteve.reinhardt@amd.com traceData->setAddr(addr); 4187045Ssteve.reinhardt@amd.com } 4197045Ssteve.reinhardt@amd.com 4207520Sgblack@eecs.umich.edu RequestPtr req = new Request(asid, addr, size, 4218832SAli.Saidi@ARM.com flags, dataMasterId(), pc, _cpuId, tid); 4225728Sgblack@eecs.umich.edu 4237520Sgblack@eecs.umich.edu Addr split_addr = roundDown(addr + size - 1, block_size); 4245744Sgblack@eecs.umich.edu assert(split_addr <= addr || split_addr - addr < block_size); 4255728Sgblack@eecs.umich.edu 4265894Sgblack@eecs.umich.edu _status = DTBWaitResponse; 4275744Sgblack@eecs.umich.edu if (split_addr > addr) { 4285894Sgblack@eecs.umich.edu RequestPtr req1, req2; 4296102Sgblack@eecs.umich.edu assert(!req->isLLSC() && !req->isSwap()); 4305894Sgblack@eecs.umich.edu req->splitOnVaddr(split_addr, req1, req2); 4315894Sgblack@eecs.umich.edu 4326973Stjones1@inf.ed.ac.uk WholeTranslationState *state = 4337520Sgblack@eecs.umich.edu new WholeTranslationState(req, req1, req2, new uint8_t[size], 4346973Stjones1@inf.ed.ac.uk NULL, mode); 4358486Sgblack@eecs.umich.edu DataTranslation<TimingSimpleCPU *> *trans1 = 4368486Sgblack@eecs.umich.edu new DataTranslation<TimingSimpleCPU *>(this, state, 0); 4378486Sgblack@eecs.umich.edu DataTranslation<TimingSimpleCPU *> *trans2 = 4388486Sgblack@eecs.umich.edu new DataTranslation<TimingSimpleCPU *>(this, state, 1); 4396973Stjones1@inf.ed.ac.uk 4406973Stjones1@inf.ed.ac.uk thread->dtb->translateTiming(req1, tc, trans1, mode); 4416973Stjones1@inf.ed.ac.uk thread->dtb->translateTiming(req2, tc, trans2, mode); 4425744Sgblack@eecs.umich.edu } else { 4436973Stjones1@inf.ed.ac.uk WholeTranslationState *state = 4447520Sgblack@eecs.umich.edu new WholeTranslationState(req, new uint8_t[size], NULL, mode); 4458486Sgblack@eecs.umich.edu DataTranslation<TimingSimpleCPU *> *translation 4468486Sgblack@eecs.umich.edu = new DataTranslation<TimingSimpleCPU *>(this, state); 4476973Stjones1@inf.ed.ac.uk thread->dtb->translateTiming(req, tc, translation, mode); 4482623SN/A } 4492623SN/A 4505728Sgblack@eecs.umich.edu return NoFault; 4512623SN/A} 4522623SN/A 4535728Sgblack@eecs.umich.edubool 4545728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket() 4555728Sgblack@eecs.umich.edu{ 4565728Sgblack@eecs.umich.edu RequestPtr req = dcache_pkt->req; 4578105Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 4589180Sandreas.hansson@arm.com Cycles delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt); 4599179Sandreas.hansson@arm.com new IprEvent(dcache_pkt, this, clockEdge(delay)); 4605728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 4615728Sgblack@eecs.umich.edu dcache_pkt = NULL; 4628975Sandreas.hansson@arm.com } else if (!dcachePort.sendTimingReq(dcache_pkt)) { 4635728Sgblack@eecs.umich.edu _status = DcacheRetry; 4645728Sgblack@eecs.umich.edu } else { 4655728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 4665728Sgblack@eecs.umich.edu // memory system takes ownership of packet 4675728Sgblack@eecs.umich.edu dcache_pkt = NULL; 4685728Sgblack@eecs.umich.edu } 4695728Sgblack@eecs.umich.edu return dcache_pkt == NULL; 4705728Sgblack@eecs.umich.edu} 4712623SN/A 4722623SN/AFault 4738444Sgblack@eecs.umich.eduTimingSimpleCPU::writeMem(uint8_t *data, unsigned size, 4748444Sgblack@eecs.umich.edu Addr addr, unsigned flags, uint64_t *res) 4752623SN/A{ 4768443Sgblack@eecs.umich.edu uint8_t *newData = new uint8_t[size]; 4778443Sgblack@eecs.umich.edu memcpy(newData, data, size); 4788443Sgblack@eecs.umich.edu 4795728Sgblack@eecs.umich.edu const int asid = 0; 4806221Snate@binkert.org const ThreadID tid = 0; 4817720Sgblack@eecs.umich.edu const Addr pc = thread->instAddr(); 4826227Snate@binkert.org unsigned block_size = dcachePort.peerBlockSize(); 4836973Stjones1@inf.ed.ac.uk BaseTLB::Mode mode = BaseTLB::Write; 4843169Sstever@eecs.umich.edu 4857045Ssteve.reinhardt@amd.com if (traceData) { 4867045Ssteve.reinhardt@amd.com traceData->setAddr(addr); 4877045Ssteve.reinhardt@amd.com } 4887045Ssteve.reinhardt@amd.com 4897520Sgblack@eecs.umich.edu RequestPtr req = new Request(asid, addr, size, 4908832SAli.Saidi@ARM.com flags, dataMasterId(), pc, _cpuId, tid); 4915728Sgblack@eecs.umich.edu 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(); 5695712Shsul@eecs.umich.edu ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0); 5705894Sgblack@eecs.umich.edu setupFetchRequest(ifetch_req); 5718277SAli.Saidi@ARM.com DPRINTF(SimpleCPU, "Translating address %#x\n", ifetch_req->getVaddr()); 5726023Snate@binkert.org thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation, 5736023Snate@binkert.org BaseTLB::Execute); 5742623SN/A } else { 5755669Sgblack@eecs.umich.edu _status = IcacheWaitResponse; 5765669Sgblack@eecs.umich.edu completeIfetch(NULL); 5775894Sgblack@eecs.umich.edu 5789179Sandreas.hansson@arm.com numCycles += curCycle() - previousCycle; 5799179Sandreas.hansson@arm.com previousCycle = curCycle(); 5805894Sgblack@eecs.umich.edu } 5815894Sgblack@eecs.umich.edu} 5825894Sgblack@eecs.umich.edu 5835894Sgblack@eecs.umich.edu 5845894Sgblack@eecs.umich.eduvoid 5855894Sgblack@eecs.umich.eduTimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc) 5865894Sgblack@eecs.umich.edu{ 5875894Sgblack@eecs.umich.edu if (fault == NoFault) { 5888277SAli.Saidi@ARM.com DPRINTF(SimpleCPU, "Sending fetch for addr %#x(pa: %#x)\n", 5898277SAli.Saidi@ARM.com req->getVaddr(), req->getPaddr()); 5908949Sandreas.hansson@arm.com ifetch_pkt = new Packet(req, MemCmd::ReadReq); 5915894Sgblack@eecs.umich.edu ifetch_pkt->dataStatic(&inst); 5928277SAli.Saidi@ARM.com DPRINTF(SimpleCPU, " -- pkt addr: %#x\n", ifetch_pkt->getAddr()); 5935894Sgblack@eecs.umich.edu 5948975Sandreas.hansson@arm.com if (!icachePort.sendTimingReq(ifetch_pkt)) { 5955894Sgblack@eecs.umich.edu // Need to wait for retry 5965894Sgblack@eecs.umich.edu _status = IcacheRetry; 5975894Sgblack@eecs.umich.edu } else { 5985894Sgblack@eecs.umich.edu // Need to wait for cache to respond 5995894Sgblack@eecs.umich.edu _status = IcacheWaitResponse; 6005894Sgblack@eecs.umich.edu // ownership of packet transferred to memory system 6015894Sgblack@eecs.umich.edu ifetch_pkt = NULL; 6025894Sgblack@eecs.umich.edu } 6035894Sgblack@eecs.umich.edu } else { 6048277SAli.Saidi@ARM.com DPRINTF(SimpleCPU, "Translation of addr %#x faulted\n", req->getVaddr()); 6055894Sgblack@eecs.umich.edu delete req; 6065894Sgblack@eecs.umich.edu // fetch fault: advance directly to next instruction (fault handler) 6079342SAndreas.Sandberg@arm.com _status = BaseSimpleCPU::Running; 6085894Sgblack@eecs.umich.edu advanceInst(fault); 6092623SN/A } 6103222Sktlim@umich.edu 6119179Sandreas.hansson@arm.com numCycles += curCycle() - previousCycle; 6129179Sandreas.hansson@arm.com previousCycle = curCycle(); 6132623SN/A} 6142623SN/A 6152623SN/A 6162623SN/Avoid 6172644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault) 6182623SN/A{ 6198276SAli.Saidi@ARM.com 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"); 6268276SAli.Saidi@ARM.com reschedule(fetchEvent, nextCycle(), 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 6359342SAndreas.Sandberg@arm.com if (_status == BaseSimpleCPU::Running) { 6362631SN/A // kick off fetch of next instruction... callback from icache 6372631SN/A // response will cause that instruction to be executed, 6382631SN/A // keeping the CPU running. 6392631SN/A fetch(); 6402631SN/A } 6412623SN/A} 6422623SN/A 6432623SN/A 6442623SN/Avoid 6453349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt) 6462623SN/A{ 6478277SAli.Saidi@ARM.com DPRINTF(SimpleCPU, "Complete ICache Fetch for addr %#x\n", pkt ? 6488277SAli.Saidi@ARM.com pkt->getAddr() : 0); 6498277SAli.Saidi@ARM.com 6502623SN/A // received a response from the icache: execute the received 6512623SN/A // instruction 6525669Sgblack@eecs.umich.edu 6535669Sgblack@eecs.umich.edu assert(!pkt || !pkt->isError()); 6542623SN/A assert(_status == IcacheWaitResponse); 6552798Sktlim@umich.edu 6569342SAndreas.Sandberg@arm.com _status = BaseSimpleCPU::Running; 6572644Sstever@eecs.umich.edu 6589179Sandreas.hansson@arm.com numCycles += curCycle() - previousCycle; 6599179Sandreas.hansson@arm.com previousCycle = curCycle(); 6603222Sktlim@umich.edu 6619342SAndreas.Sandberg@arm.com if (getDrainState() == Drainable::Draining) { 6625669Sgblack@eecs.umich.edu if (pkt) { 6635669Sgblack@eecs.umich.edu delete pkt->req; 6645669Sgblack@eecs.umich.edu delete pkt; 6655669Sgblack@eecs.umich.edu } 6663658Sktlim@umich.edu 6672839Sktlim@umich.edu completeDrain(); 6682798Sktlim@umich.edu return; 6692798Sktlim@umich.edu } 6702798Sktlim@umich.edu 6712623SN/A preExecute(); 6727725SAli.Saidi@ARM.com if (curStaticInst && curStaticInst->isMemRef()) { 6732623SN/A // load or store: just send to dcache 6742623SN/A Fault fault = curStaticInst->initiateAcc(this, traceData); 6757945SAli.Saidi@ARM.com 6767945SAli.Saidi@ARM.com // If we're not running now the instruction will complete in a dcache 6777945SAli.Saidi@ARM.com // response callback or the instruction faulted and has started an 6787945SAli.Saidi@ARM.com // ifetch 6799342SAndreas.Sandberg@arm.com if (_status == BaseSimpleCPU::Running) { 6805894Sgblack@eecs.umich.edu if (fault != NoFault && traceData) { 6815001Sgblack@eecs.umich.edu // If there was a fault, we shouldn't trace this instruction. 6825001Sgblack@eecs.umich.edu delete traceData; 6835001Sgblack@eecs.umich.edu traceData = NULL; 6843170Sstever@eecs.umich.edu } 6854998Sgblack@eecs.umich.edu 6862644Sstever@eecs.umich.edu postExecute(); 6875103Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 6885103Ssaidi@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 6895103Ssaidi@eecs.umich.edu curStaticInst->isFirstMicroop())) 6905103Ssaidi@eecs.umich.edu instCnt++; 6912644Sstever@eecs.umich.edu advanceInst(fault); 6922644Sstever@eecs.umich.edu } 6935726Sgblack@eecs.umich.edu } else if (curStaticInst) { 6942623SN/A // non-memory instruction: execute completely now 6952623SN/A Fault fault = curStaticInst->execute(this, traceData); 6964998Sgblack@eecs.umich.edu 6974998Sgblack@eecs.umich.edu // keep an instruction count 6984998Sgblack@eecs.umich.edu if (fault == NoFault) 6994998Sgblack@eecs.umich.edu countInst(); 7007655Sali.saidi@arm.com else if (traceData && !DTRACE(ExecFaulting)) { 7015001Sgblack@eecs.umich.edu delete traceData; 7025001Sgblack@eecs.umich.edu traceData = NULL; 7035001Sgblack@eecs.umich.edu } 7044998Sgblack@eecs.umich.edu 7052644Sstever@eecs.umich.edu postExecute(); 7065103Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 7075103Ssaidi@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 7085103Ssaidi@eecs.umich.edu curStaticInst->isFirstMicroop())) 7095103Ssaidi@eecs.umich.edu instCnt++; 7102644Sstever@eecs.umich.edu advanceInst(fault); 7115726Sgblack@eecs.umich.edu } else { 7125726Sgblack@eecs.umich.edu advanceInst(NoFault); 7132623SN/A } 7143658Sktlim@umich.edu 7155669Sgblack@eecs.umich.edu if (pkt) { 7165669Sgblack@eecs.umich.edu delete pkt->req; 7175669Sgblack@eecs.umich.edu delete pkt; 7185669Sgblack@eecs.umich.edu } 7192623SN/A} 7202623SN/A 7212948Ssaidi@eecs.umich.eduvoid 7222948Ssaidi@eecs.umich.eduTimingSimpleCPU::IcachePort::ITickEvent::process() 7232948Ssaidi@eecs.umich.edu{ 7242948Ssaidi@eecs.umich.edu cpu->completeIfetch(pkt); 7252948Ssaidi@eecs.umich.edu} 7262623SN/A 7272623SN/Abool 7288975Sandreas.hansson@arm.comTimingSimpleCPU::IcachePort::recvTimingResp(PacketPtr pkt) 7292623SN/A{ 7309165Sandreas.hansson@arm.com DPRINTF(SimpleCPU, "Received timing response %#x\n", pkt->getAddr()); 7319165Sandreas.hansson@arm.com // delay processing of returned data until next CPU clock edge 7329165Sandreas.hansson@arm.com Tick next_tick = cpu->nextCycle(); 7332948Ssaidi@eecs.umich.edu 7349165Sandreas.hansson@arm.com if (next_tick == curTick()) 7359165Sandreas.hansson@arm.com cpu->completeIfetch(pkt); 7369165Sandreas.hansson@arm.com else 7379165Sandreas.hansson@arm.com tickEvent.schedule(pkt, next_tick); 7388948Sandreas.hansson@arm.com 7394433Ssaidi@eecs.umich.edu return true; 7402623SN/A} 7412623SN/A 7422657Ssaidi@eecs.umich.eduvoid 7432623SN/ATimingSimpleCPU::IcachePort::recvRetry() 7442623SN/A{ 7452623SN/A // we shouldn't get a retry unless we have a packet that we're 7462623SN/A // waiting to transmit 7472623SN/A assert(cpu->ifetch_pkt != NULL); 7482623SN/A assert(cpu->_status == IcacheRetry); 7493349Sbinkertn@umich.edu PacketPtr tmp = cpu->ifetch_pkt; 7508975Sandreas.hansson@arm.com if (sendTimingReq(tmp)) { 7512657Ssaidi@eecs.umich.edu cpu->_status = IcacheWaitResponse; 7522657Ssaidi@eecs.umich.edu cpu->ifetch_pkt = NULL; 7532657Ssaidi@eecs.umich.edu } 7542623SN/A} 7552623SN/A 7562623SN/Avoid 7573349Sbinkertn@umich.eduTimingSimpleCPU::completeDataAccess(PacketPtr pkt) 7582623SN/A{ 7592623SN/A // received a response from the dcache: complete the load or store 7602623SN/A // instruction 7614870Sstever@eecs.umich.edu assert(!pkt->isError()); 7627516Shestness@cs.utexas.edu assert(_status == DcacheWaitResponse || _status == DTBWaitResponse || 7637516Shestness@cs.utexas.edu pkt->req->getFlags().isSet(Request::NO_ACCESS)); 7642623SN/A 7659179Sandreas.hansson@arm.com numCycles += curCycle() - previousCycle; 7669179Sandreas.hansson@arm.com previousCycle = curCycle(); 7673184Srdreslin@umich.edu 7685728Sgblack@eecs.umich.edu if (pkt->senderState) { 7695728Sgblack@eecs.umich.edu SplitFragmentSenderState * send_state = 7705728Sgblack@eecs.umich.edu dynamic_cast<SplitFragmentSenderState *>(pkt->senderState); 7715728Sgblack@eecs.umich.edu assert(send_state); 7725728Sgblack@eecs.umich.edu delete pkt->req; 7735728Sgblack@eecs.umich.edu delete pkt; 7745728Sgblack@eecs.umich.edu PacketPtr big_pkt = send_state->bigPkt; 7755728Sgblack@eecs.umich.edu delete send_state; 7765728Sgblack@eecs.umich.edu 7775728Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = 7785728Sgblack@eecs.umich.edu dynamic_cast<SplitMainSenderState *>(big_pkt->senderState); 7795728Sgblack@eecs.umich.edu assert(main_send_state); 7805728Sgblack@eecs.umich.edu // Record the fact that this packet is no longer outstanding. 7815728Sgblack@eecs.umich.edu assert(main_send_state->outstanding != 0); 7825728Sgblack@eecs.umich.edu main_send_state->outstanding--; 7835728Sgblack@eecs.umich.edu 7845728Sgblack@eecs.umich.edu if (main_send_state->outstanding) { 7855728Sgblack@eecs.umich.edu return; 7865728Sgblack@eecs.umich.edu } else { 7875728Sgblack@eecs.umich.edu delete main_send_state; 7885728Sgblack@eecs.umich.edu big_pkt->senderState = NULL; 7895728Sgblack@eecs.umich.edu pkt = big_pkt; 7905728Sgblack@eecs.umich.edu } 7915728Sgblack@eecs.umich.edu } 7925728Sgblack@eecs.umich.edu 7939342SAndreas.Sandberg@arm.com _status = BaseSimpleCPU::Running; 7945728Sgblack@eecs.umich.edu 7952623SN/A Fault fault = curStaticInst->completeAcc(pkt, this, traceData); 7962623SN/A 7974998Sgblack@eecs.umich.edu // keep an instruction count 7984998Sgblack@eecs.umich.edu if (fault == NoFault) 7994998Sgblack@eecs.umich.edu countInst(); 8005001Sgblack@eecs.umich.edu else if (traceData) { 8015001Sgblack@eecs.umich.edu // If there was a fault, we shouldn't trace this instruction. 8025001Sgblack@eecs.umich.edu delete traceData; 8035001Sgblack@eecs.umich.edu traceData = NULL; 8045001Sgblack@eecs.umich.edu } 8054998Sgblack@eecs.umich.edu 8065507Sstever@gmail.com // the locked flag may be cleared on the response packet, so check 8075507Sstever@gmail.com // pkt->req and not pkt to see if it was a load-locked 8086102Sgblack@eecs.umich.edu if (pkt->isRead() && pkt->req->isLLSC()) { 8093170Sstever@eecs.umich.edu TheISA::handleLockedRead(thread, pkt->req); 8103170Sstever@eecs.umich.edu } 8113170Sstever@eecs.umich.edu 8122644Sstever@eecs.umich.edu delete pkt->req; 8132644Sstever@eecs.umich.edu delete pkt; 8142644Sstever@eecs.umich.edu 8153184Srdreslin@umich.edu postExecute(); 8163227Sktlim@umich.edu 8179342SAndreas.Sandberg@arm.com if (getDrainState() == Drainable::Draining) { 8183201Shsul@eecs.umich.edu advancePC(fault); 8193201Shsul@eecs.umich.edu completeDrain(); 8203201Shsul@eecs.umich.edu 8213201Shsul@eecs.umich.edu return; 8223201Shsul@eecs.umich.edu } 8233201Shsul@eecs.umich.edu 8242644Sstever@eecs.umich.edu advanceInst(fault); 8252623SN/A} 8262623SN/A 8272623SN/A 8282798Sktlim@umich.eduvoid 8292839Sktlim@umich.eduTimingSimpleCPU::completeDrain() 8302798Sktlim@umich.edu{ 8319152Satgutier@umich.edu DPRINTF(Drain, "CPU done draining, processing drain event\n"); 8329342SAndreas.Sandberg@arm.com setDrainState(Drainable::Drained); 8339342SAndreas.Sandberg@arm.com drainManager->signalDrainDone(); 8342798Sktlim@umich.edu} 8352623SN/A 8362623SN/Abool 8378975Sandreas.hansson@arm.comTimingSimpleCPU::DcachePort::recvTimingResp(PacketPtr pkt) 8382623SN/A{ 8399165Sandreas.hansson@arm.com // delay processing of returned data until next CPU clock edge 8409165Sandreas.hansson@arm.com Tick next_tick = cpu->nextCycle(); 8412948Ssaidi@eecs.umich.edu 8429165Sandreas.hansson@arm.com if (next_tick == curTick()) { 8439165Sandreas.hansson@arm.com cpu->completeDataAccess(pkt); 8449165Sandreas.hansson@arm.com } else { 8459165Sandreas.hansson@arm.com if (!tickEvent.scheduled()) { 8469165Sandreas.hansson@arm.com tickEvent.schedule(pkt, next_tick); 8475728Sgblack@eecs.umich.edu } else { 8489165Sandreas.hansson@arm.com // In the case of a split transaction and a cache that is 8499165Sandreas.hansson@arm.com // faster than a CPU we could get two responses before 8509165Sandreas.hansson@arm.com // next_tick expires 8519165Sandreas.hansson@arm.com if (!retryEvent.scheduled()) 8529165Sandreas.hansson@arm.com cpu->schedule(retryEvent, next_tick); 8539165Sandreas.hansson@arm.com return false; 8544433Ssaidi@eecs.umich.edu } 8553310Srdreslin@umich.edu } 8568948Sandreas.hansson@arm.com 8574433Ssaidi@eecs.umich.edu return true; 8582948Ssaidi@eecs.umich.edu} 8592948Ssaidi@eecs.umich.edu 8602948Ssaidi@eecs.umich.eduvoid 8612948Ssaidi@eecs.umich.eduTimingSimpleCPU::DcachePort::DTickEvent::process() 8622948Ssaidi@eecs.umich.edu{ 8632630SN/A cpu->completeDataAccess(pkt); 8642623SN/A} 8652623SN/A 8662657Ssaidi@eecs.umich.eduvoid 8672623SN/ATimingSimpleCPU::DcachePort::recvRetry() 8682623SN/A{ 8692623SN/A // we shouldn't get a retry unless we have a packet that we're 8702623SN/A // waiting to transmit 8712623SN/A assert(cpu->dcache_pkt != NULL); 8722623SN/A assert(cpu->_status == DcacheRetry); 8733349Sbinkertn@umich.edu PacketPtr tmp = cpu->dcache_pkt; 8745728Sgblack@eecs.umich.edu if (tmp->senderState) { 8755728Sgblack@eecs.umich.edu // This is a packet from a split access. 8765728Sgblack@eecs.umich.edu SplitFragmentSenderState * send_state = 8775728Sgblack@eecs.umich.edu dynamic_cast<SplitFragmentSenderState *>(tmp->senderState); 8785728Sgblack@eecs.umich.edu assert(send_state); 8795728Sgblack@eecs.umich.edu PacketPtr big_pkt = send_state->bigPkt; 8805728Sgblack@eecs.umich.edu 8815728Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = 8825728Sgblack@eecs.umich.edu dynamic_cast<SplitMainSenderState *>(big_pkt->senderState); 8835728Sgblack@eecs.umich.edu assert(main_send_state); 8845728Sgblack@eecs.umich.edu 8858975Sandreas.hansson@arm.com if (sendTimingReq(tmp)) { 8865728Sgblack@eecs.umich.edu // If we were able to send without retrying, record that fact 8875728Sgblack@eecs.umich.edu // and try sending the other fragment. 8885728Sgblack@eecs.umich.edu send_state->clearFromParent(); 8895728Sgblack@eecs.umich.edu int other_index = main_send_state->getPendingFragment(); 8905728Sgblack@eecs.umich.edu if (other_index > 0) { 8915728Sgblack@eecs.umich.edu tmp = main_send_state->fragments[other_index]; 8925728Sgblack@eecs.umich.edu cpu->dcache_pkt = tmp; 8935728Sgblack@eecs.umich.edu if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) || 8945728Sgblack@eecs.umich.edu (big_pkt->isWrite() && cpu->handleWritePacket())) { 8955728Sgblack@eecs.umich.edu main_send_state->fragments[other_index] = NULL; 8965728Sgblack@eecs.umich.edu } 8975728Sgblack@eecs.umich.edu } else { 8985728Sgblack@eecs.umich.edu cpu->_status = DcacheWaitResponse; 8995728Sgblack@eecs.umich.edu // memory system takes ownership of packet 9005728Sgblack@eecs.umich.edu cpu->dcache_pkt = NULL; 9015728Sgblack@eecs.umich.edu } 9025728Sgblack@eecs.umich.edu } 9038975Sandreas.hansson@arm.com } else if (sendTimingReq(tmp)) { 9042657Ssaidi@eecs.umich.edu cpu->_status = DcacheWaitResponse; 9053170Sstever@eecs.umich.edu // memory system takes ownership of packet 9062657Ssaidi@eecs.umich.edu cpu->dcache_pkt = NULL; 9072657Ssaidi@eecs.umich.edu } 9082623SN/A} 9092623SN/A 9105606Snate@binkert.orgTimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, 9115606Snate@binkert.org Tick t) 9125606Snate@binkert.org : pkt(_pkt), cpu(_cpu) 9135103Ssaidi@eecs.umich.edu{ 9145606Snate@binkert.org cpu->schedule(this, t); 9155103Ssaidi@eecs.umich.edu} 9165103Ssaidi@eecs.umich.edu 9175103Ssaidi@eecs.umich.eduvoid 9185103Ssaidi@eecs.umich.eduTimingSimpleCPU::IprEvent::process() 9195103Ssaidi@eecs.umich.edu{ 9205103Ssaidi@eecs.umich.edu cpu->completeDataAccess(pkt); 9215103Ssaidi@eecs.umich.edu} 9225103Ssaidi@eecs.umich.edu 9235103Ssaidi@eecs.umich.educonst char * 9245336Shines@cs.fsu.eduTimingSimpleCPU::IprEvent::description() const 9255103Ssaidi@eecs.umich.edu{ 9265103Ssaidi@eecs.umich.edu return "Timing Simple CPU Delay IPR event"; 9275103Ssaidi@eecs.umich.edu} 9285103Ssaidi@eecs.umich.edu 9292623SN/A 9305315Sstever@gmail.comvoid 9315315Sstever@gmail.comTimingSimpleCPU::printAddr(Addr a) 9325315Sstever@gmail.com{ 9335315Sstever@gmail.com dcachePort.printAddr(a); 9345315Sstever@gmail.com} 9355315Sstever@gmail.com 9365315Sstever@gmail.com 9372623SN/A//////////////////////////////////////////////////////////////////////// 9382623SN/A// 9392623SN/A// TimingSimpleCPU Simulation Object 9402623SN/A// 9414762Snate@binkert.orgTimingSimpleCPU * 9424762Snate@binkert.orgTimingSimpleCPUParams::create() 9432623SN/A{ 9445529Snate@binkert.org numThreads = 1; 9458779Sgblack@eecs.umich.edu if (!FullSystem && workload.size() != 1) 9464762Snate@binkert.org panic("only one workload allowed"); 9475529Snate@binkert.org return new TimingSimpleCPU(this); 9482623SN/A} 949