timing.cc revision 6658
12623SN/A/* 22623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32623SN/A * All rights reserved. 42623SN/A * 52623SN/A * Redistribution and use in source and binary forms, with or without 62623SN/A * modification, are permitted provided that the following conditions are 72623SN/A * met: redistributions of source code must retain the above copyright 82623SN/A * notice, this list of conditions and the following disclaimer; 92623SN/A * redistributions in binary form must reproduce the above copyright 102623SN/A * notice, this list of conditions and the following disclaimer in the 112623SN/A * documentation and/or other materials provided with the distribution; 122623SN/A * neither the name of the copyright holders nor the names of its 132623SN/A * contributors may be used to endorse or promote products derived from 142623SN/A * this software without specific prior written permission. 152623SN/A * 162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292623SN/A */ 302623SN/A 313170Sstever@eecs.umich.edu#include "arch/locked_mem.hh" 325103Ssaidi@eecs.umich.edu#include "arch/mmaped_ipr.hh" 332623SN/A#include "arch/utility.hh" 344040Ssaidi@eecs.umich.edu#include "base/bigint.hh" 356658Snate@binkert.org#include "config/the_isa.hh" 362623SN/A#include "cpu/exetrace.hh" 372623SN/A#include "cpu/simple/timing.hh" 383348Sbinkertn@umich.edu#include "mem/packet.hh" 393348Sbinkertn@umich.edu#include "mem/packet_access.hh" 404762Snate@binkert.org#include "params/TimingSimpleCPU.hh" 412901Ssaidi@eecs.umich.edu#include "sim/system.hh" 422623SN/A 432623SN/Ausing namespace std; 442623SN/Ausing namespace TheISA; 452623SN/A 462856Srdreslin@umich.eduPort * 472856Srdreslin@umich.eduTimingSimpleCPU::getPort(const std::string &if_name, int idx) 482856Srdreslin@umich.edu{ 492856Srdreslin@umich.edu if (if_name == "dcache_port") 502856Srdreslin@umich.edu return &dcachePort; 512856Srdreslin@umich.edu else if (if_name == "icache_port") 522856Srdreslin@umich.edu return &icachePort; 532856Srdreslin@umich.edu else 542856Srdreslin@umich.edu panic("No Such Port\n"); 552856Srdreslin@umich.edu} 562623SN/A 572623SN/Avoid 582623SN/ATimingSimpleCPU::init() 592623SN/A{ 602623SN/A BaseCPU::init(); 612623SN/A#if FULL_SYSTEM 622680Sktlim@umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 632680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 642623SN/A 652623SN/A // initialize CPU, including PC 665712Shsul@eecs.umich.edu TheISA::initCPU(tc, _cpuId); 672623SN/A } 682623SN/A#endif 692623SN/A} 702623SN/A 712623SN/ATick 723349Sbinkertn@umich.eduTimingSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt) 732623SN/A{ 742623SN/A panic("TimingSimpleCPU doesn't expect recvAtomic callback!"); 752623SN/A return curTick; 762623SN/A} 772623SN/A 782623SN/Avoid 793349Sbinkertn@umich.eduTimingSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt) 802623SN/A{ 813184Srdreslin@umich.edu //No internal storage to update, jusst return 823184Srdreslin@umich.edu return; 832623SN/A} 842623SN/A 852623SN/Avoid 862623SN/ATimingSimpleCPU::CpuPort::recvStatusChange(Status status) 872623SN/A{ 883647Srdreslin@umich.edu if (status == RangeChange) { 893647Srdreslin@umich.edu if (!snoopRangeSent) { 903647Srdreslin@umich.edu snoopRangeSent = true; 913647Srdreslin@umich.edu sendStatusChange(Port::RangeChange); 923647Srdreslin@umich.edu } 932631SN/A return; 943647Srdreslin@umich.edu } 952631SN/A 962623SN/A panic("TimingSimpleCPU doesn't expect recvStatusChange callback!"); 972623SN/A} 982623SN/A 992948Ssaidi@eecs.umich.edu 1002948Ssaidi@eecs.umich.eduvoid 1013349Sbinkertn@umich.eduTimingSimpleCPU::CpuPort::TickEvent::schedule(PacketPtr _pkt, Tick t) 1022948Ssaidi@eecs.umich.edu{ 1032948Ssaidi@eecs.umich.edu pkt = _pkt; 1045606Snate@binkert.org cpu->schedule(this, t); 1052948Ssaidi@eecs.umich.edu} 1062948Ssaidi@eecs.umich.edu 1075529Snate@binkert.orgTimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams *p) 1085894Sgblack@eecs.umich.edu : BaseSimpleCPU(p), fetchTranslation(this), icachePort(this, p->clock), 1095894Sgblack@eecs.umich.edu dcachePort(this, p->clock), fetchEvent(this) 1102623SN/A{ 1112623SN/A _status = Idle; 1123647Srdreslin@umich.edu 1133647Srdreslin@umich.edu icachePort.snoopRangeSent = false; 1143647Srdreslin@umich.edu dcachePort.snoopRangeSent = false; 1153647Srdreslin@umich.edu 1162623SN/A ifetch_pkt = dcache_pkt = NULL; 1172839Sktlim@umich.edu drainEvent = NULL; 1183222Sktlim@umich.edu previousTick = 0; 1192901Ssaidi@eecs.umich.edu changeState(SimObject::Running); 1202623SN/A} 1212623SN/A 1222623SN/A 1232623SN/ATimingSimpleCPU::~TimingSimpleCPU() 1242623SN/A{ 1252623SN/A} 1262623SN/A 1272623SN/Avoid 1282623SN/ATimingSimpleCPU::serialize(ostream &os) 1292623SN/A{ 1302915Sktlim@umich.edu SimObject::State so_state = SimObject::getState(); 1312915Sktlim@umich.edu SERIALIZE_ENUM(so_state); 1322623SN/A BaseSimpleCPU::serialize(os); 1332623SN/A} 1342623SN/A 1352623SN/Avoid 1362623SN/ATimingSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 1372623SN/A{ 1382915Sktlim@umich.edu SimObject::State so_state; 1392915Sktlim@umich.edu UNSERIALIZE_ENUM(so_state); 1402623SN/A BaseSimpleCPU::unserialize(cp, section); 1412798Sktlim@umich.edu} 1422798Sktlim@umich.edu 1432901Ssaidi@eecs.umich.eduunsigned int 1442839Sktlim@umich.eduTimingSimpleCPU::drain(Event *drain_event) 1452798Sktlim@umich.edu{ 1462839Sktlim@umich.edu // TimingSimpleCPU is ready to drain if it's not waiting for 1472798Sktlim@umich.edu // an access to complete. 1485496Ssaidi@eecs.umich.edu if (_status == Idle || _status == Running || _status == SwitchedOut) { 1492901Ssaidi@eecs.umich.edu changeState(SimObject::Drained); 1502901Ssaidi@eecs.umich.edu return 0; 1512798Sktlim@umich.edu } else { 1522839Sktlim@umich.edu changeState(SimObject::Draining); 1532839Sktlim@umich.edu drainEvent = drain_event; 1542901Ssaidi@eecs.umich.edu return 1; 1552798Sktlim@umich.edu } 1562623SN/A} 1572623SN/A 1582623SN/Avoid 1592798Sktlim@umich.eduTimingSimpleCPU::resume() 1602623SN/A{ 1615221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "Resume\n"); 1622798Sktlim@umich.edu if (_status != SwitchedOut && _status != Idle) { 1634762Snate@binkert.org assert(system->getMemoryMode() == Enums::timing); 1643201Shsul@eecs.umich.edu 1655710Scws3k@cs.virginia.edu if (fetchEvent.scheduled()) 1665710Scws3k@cs.virginia.edu deschedule(fetchEvent); 1672915Sktlim@umich.edu 1685710Scws3k@cs.virginia.edu schedule(fetchEvent, nextCycle()); 1692623SN/A } 1702798Sktlim@umich.edu 1712901Ssaidi@eecs.umich.edu changeState(SimObject::Running); 1722798Sktlim@umich.edu} 1732798Sktlim@umich.edu 1742798Sktlim@umich.eduvoid 1752798Sktlim@umich.eduTimingSimpleCPU::switchOut() 1762798Sktlim@umich.edu{ 1775496Ssaidi@eecs.umich.edu assert(_status == Running || _status == Idle); 1782798Sktlim@umich.edu _status = SwitchedOut; 1795099Ssaidi@eecs.umich.edu numCycles += tickToCycles(curTick - previousTick); 1802867Sktlim@umich.edu 1812867Sktlim@umich.edu // If we've been scheduled to resume but are then told to switch out, 1822867Sktlim@umich.edu // we'll need to cancel it. 1835710Scws3k@cs.virginia.edu if (fetchEvent.scheduled()) 1845606Snate@binkert.org deschedule(fetchEvent); 1852623SN/A} 1862623SN/A 1872623SN/A 1882623SN/Avoid 1892623SN/ATimingSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 1902623SN/A{ 1914192Sktlim@umich.edu BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort); 1922623SN/A 1932680Sktlim@umich.edu // if any of this CPU's ThreadContexts are active, mark the CPU as 1942623SN/A // running and schedule its tick event. 1952680Sktlim@umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 1962680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 1972680Sktlim@umich.edu if (tc->status() == ThreadContext::Active && _status != Running) { 1982623SN/A _status = Running; 1992623SN/A break; 2002623SN/A } 2012623SN/A } 2023201Shsul@eecs.umich.edu 2033201Shsul@eecs.umich.edu if (_status != Running) { 2043201Shsul@eecs.umich.edu _status = Idle; 2053201Shsul@eecs.umich.edu } 2065169Ssaidi@eecs.umich.edu assert(threadContexts.size() == 1); 2075101Ssaidi@eecs.umich.edu previousTick = curTick; 2082623SN/A} 2092623SN/A 2102623SN/A 2112623SN/Avoid 2122623SN/ATimingSimpleCPU::activateContext(int thread_num, int delay) 2132623SN/A{ 2145221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay); 2155221Ssaidi@eecs.umich.edu 2162623SN/A assert(thread_num == 0); 2172683Sktlim@umich.edu assert(thread); 2182623SN/A 2192623SN/A assert(_status == Idle); 2202623SN/A 2212623SN/A notIdleFraction++; 2222623SN/A _status = Running; 2233686Sktlim@umich.edu 2242623SN/A // kick things off by initiating the fetch of the next instruction 2255606Snate@binkert.org schedule(fetchEvent, nextCycle(curTick + ticks(delay))); 2262623SN/A} 2272623SN/A 2282623SN/A 2292623SN/Avoid 2302623SN/ATimingSimpleCPU::suspendContext(int thread_num) 2312623SN/A{ 2325221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num); 2335221Ssaidi@eecs.umich.edu 2342623SN/A assert(thread_num == 0); 2352683Sktlim@umich.edu assert(thread); 2362623SN/A 2376043Sgblack@eecs.umich.edu if (_status == Idle) 2386043Sgblack@eecs.umich.edu return; 2396043Sgblack@eecs.umich.edu 2402644Sstever@eecs.umich.edu assert(_status == Running); 2412623SN/A 2422644Sstever@eecs.umich.edu // just change status to Idle... if status != Running, 2432644Sstever@eecs.umich.edu // completeInst() will not initiate fetch of next instruction. 2442623SN/A 2452623SN/A notIdleFraction--; 2462623SN/A _status = Idle; 2472623SN/A} 2482623SN/A 2495728Sgblack@eecs.umich.edubool 2505728Sgblack@eecs.umich.eduTimingSimpleCPU::handleReadPacket(PacketPtr pkt) 2515728Sgblack@eecs.umich.edu{ 2525728Sgblack@eecs.umich.edu RequestPtr req = pkt->req; 2535728Sgblack@eecs.umich.edu if (req->isMmapedIpr()) { 2545728Sgblack@eecs.umich.edu Tick delay; 2555728Sgblack@eecs.umich.edu delay = TheISA::handleIprRead(thread->getTC(), pkt); 2565728Sgblack@eecs.umich.edu new IprEvent(pkt, this, nextCycle(curTick + delay)); 2575728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 2585728Sgblack@eecs.umich.edu dcache_pkt = NULL; 2595728Sgblack@eecs.umich.edu } else if (!dcachePort.sendTiming(pkt)) { 2605728Sgblack@eecs.umich.edu _status = DcacheRetry; 2615728Sgblack@eecs.umich.edu dcache_pkt = pkt; 2625728Sgblack@eecs.umich.edu } else { 2635728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 2645728Sgblack@eecs.umich.edu // memory system takes ownership of packet 2655728Sgblack@eecs.umich.edu dcache_pkt = NULL; 2665728Sgblack@eecs.umich.edu } 2675728Sgblack@eecs.umich.edu return dcache_pkt == NULL; 2685728Sgblack@eecs.umich.edu} 2692623SN/A 2705894Sgblack@eecs.umich.eduvoid 2715894Sgblack@eecs.umich.eduTimingSimpleCPU::sendData(Fault fault, RequestPtr req, 2725894Sgblack@eecs.umich.edu uint8_t *data, uint64_t *res, bool read) 2735744Sgblack@eecs.umich.edu{ 2745894Sgblack@eecs.umich.edu _status = Running; 2755894Sgblack@eecs.umich.edu if (fault != NoFault) { 2765894Sgblack@eecs.umich.edu delete data; 2775894Sgblack@eecs.umich.edu delete req; 2785744Sgblack@eecs.umich.edu 2795894Sgblack@eecs.umich.edu translationFault(fault); 2805894Sgblack@eecs.umich.edu return; 2815894Sgblack@eecs.umich.edu } 2825894Sgblack@eecs.umich.edu PacketPtr pkt; 2835894Sgblack@eecs.umich.edu buildPacket(pkt, req, read); 2845894Sgblack@eecs.umich.edu pkt->dataDynamic<uint8_t>(data); 2855894Sgblack@eecs.umich.edu if (req->getFlags().isSet(Request::NO_ACCESS)) { 2865894Sgblack@eecs.umich.edu assert(!dcache_pkt); 2875894Sgblack@eecs.umich.edu pkt->makeResponse(); 2885894Sgblack@eecs.umich.edu completeDataAccess(pkt); 2895894Sgblack@eecs.umich.edu } else if (read) { 2905894Sgblack@eecs.umich.edu handleReadPacket(pkt); 2915894Sgblack@eecs.umich.edu } else { 2925894Sgblack@eecs.umich.edu bool do_access = true; // flag to suppress cache access 2935894Sgblack@eecs.umich.edu 2946102Sgblack@eecs.umich.edu if (req->isLLSC()) { 2955894Sgblack@eecs.umich.edu do_access = TheISA::handleLockedWrite(thread, req); 2965894Sgblack@eecs.umich.edu } else if (req->isCondSwap()) { 2975894Sgblack@eecs.umich.edu assert(res); 2985894Sgblack@eecs.umich.edu req->setExtraData(*res); 2995894Sgblack@eecs.umich.edu } 3005894Sgblack@eecs.umich.edu 3015894Sgblack@eecs.umich.edu if (do_access) { 3025894Sgblack@eecs.umich.edu dcache_pkt = pkt; 3035894Sgblack@eecs.umich.edu handleWritePacket(); 3045894Sgblack@eecs.umich.edu } else { 3055894Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 3065894Sgblack@eecs.umich.edu completeDataAccess(pkt); 3075894Sgblack@eecs.umich.edu } 3085894Sgblack@eecs.umich.edu } 3095894Sgblack@eecs.umich.edu} 3105894Sgblack@eecs.umich.edu 3115894Sgblack@eecs.umich.eduvoid 3125894Sgblack@eecs.umich.eduTimingSimpleCPU::sendSplitData(Fault fault1, Fault fault2, 3135894Sgblack@eecs.umich.edu RequestPtr req1, RequestPtr req2, RequestPtr req, 3145894Sgblack@eecs.umich.edu uint8_t *data, bool read) 3155894Sgblack@eecs.umich.edu{ 3165894Sgblack@eecs.umich.edu _status = Running; 3175894Sgblack@eecs.umich.edu if (fault1 != NoFault || fault2 != NoFault) { 3185894Sgblack@eecs.umich.edu delete data; 3195890Sgblack@eecs.umich.edu delete req1; 3205894Sgblack@eecs.umich.edu delete req2; 3215894Sgblack@eecs.umich.edu if (fault1 != NoFault) 3225894Sgblack@eecs.umich.edu translationFault(fault1); 3235894Sgblack@eecs.umich.edu else if (fault2 != NoFault) 3245894Sgblack@eecs.umich.edu translationFault(fault2); 3255894Sgblack@eecs.umich.edu return; 3265894Sgblack@eecs.umich.edu } 3275894Sgblack@eecs.umich.edu PacketPtr pkt1, pkt2; 3285894Sgblack@eecs.umich.edu buildSplitPacket(pkt1, pkt2, req1, req2, req, data, read); 3295894Sgblack@eecs.umich.edu if (req->getFlags().isSet(Request::NO_ACCESS)) { 3305894Sgblack@eecs.umich.edu assert(!dcache_pkt); 3315894Sgblack@eecs.umich.edu pkt1->makeResponse(); 3325894Sgblack@eecs.umich.edu completeDataAccess(pkt1); 3335894Sgblack@eecs.umich.edu } else if (read) { 3345894Sgblack@eecs.umich.edu if (handleReadPacket(pkt1)) { 3355894Sgblack@eecs.umich.edu SplitFragmentSenderState * send_state = 3365894Sgblack@eecs.umich.edu dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState); 3375894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3385894Sgblack@eecs.umich.edu if (handleReadPacket(pkt2)) { 3395894Sgblack@eecs.umich.edu send_state = dynamic_cast<SplitFragmentSenderState *>( 3405894Sgblack@eecs.umich.edu pkt1->senderState); 3415894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3425894Sgblack@eecs.umich.edu } 3435894Sgblack@eecs.umich.edu } 3445894Sgblack@eecs.umich.edu } else { 3455894Sgblack@eecs.umich.edu dcache_pkt = pkt1; 3465894Sgblack@eecs.umich.edu if (handleWritePacket()) { 3475894Sgblack@eecs.umich.edu SplitFragmentSenderState * send_state = 3485894Sgblack@eecs.umich.edu dynamic_cast<SplitFragmentSenderState *>(pkt1->senderState); 3495894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3505894Sgblack@eecs.umich.edu dcache_pkt = pkt2; 3515894Sgblack@eecs.umich.edu if (handleWritePacket()) { 3525894Sgblack@eecs.umich.edu send_state = dynamic_cast<SplitFragmentSenderState *>( 3535894Sgblack@eecs.umich.edu pkt1->senderState); 3545894Sgblack@eecs.umich.edu send_state->clearFromParent(); 3555894Sgblack@eecs.umich.edu } 3565894Sgblack@eecs.umich.edu } 3575894Sgblack@eecs.umich.edu } 3585894Sgblack@eecs.umich.edu} 3595894Sgblack@eecs.umich.edu 3605894Sgblack@eecs.umich.eduvoid 3615894Sgblack@eecs.umich.eduTimingSimpleCPU::translationFault(Fault fault) 3625894Sgblack@eecs.umich.edu{ 3635894Sgblack@eecs.umich.edu numCycles += tickToCycles(curTick - previousTick); 3645894Sgblack@eecs.umich.edu previousTick = curTick; 3655894Sgblack@eecs.umich.edu 3665894Sgblack@eecs.umich.edu if (traceData) { 3675894Sgblack@eecs.umich.edu // Since there was a fault, we shouldn't trace this instruction. 3685894Sgblack@eecs.umich.edu delete traceData; 3695894Sgblack@eecs.umich.edu traceData = NULL; 3705744Sgblack@eecs.umich.edu } 3715744Sgblack@eecs.umich.edu 3725894Sgblack@eecs.umich.edu postExecute(); 3735894Sgblack@eecs.umich.edu 3745894Sgblack@eecs.umich.edu if (getState() == SimObject::Draining) { 3755894Sgblack@eecs.umich.edu advancePC(fault); 3765894Sgblack@eecs.umich.edu completeDrain(); 3775894Sgblack@eecs.umich.edu } else { 3785894Sgblack@eecs.umich.edu advanceInst(fault); 3795894Sgblack@eecs.umich.edu } 3805894Sgblack@eecs.umich.edu} 3815894Sgblack@eecs.umich.edu 3825894Sgblack@eecs.umich.eduvoid 3835894Sgblack@eecs.umich.eduTimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read) 3845894Sgblack@eecs.umich.edu{ 3855894Sgblack@eecs.umich.edu MemCmd cmd; 3865894Sgblack@eecs.umich.edu if (read) { 3875894Sgblack@eecs.umich.edu cmd = MemCmd::ReadReq; 3886102Sgblack@eecs.umich.edu if (req->isLLSC()) 3895894Sgblack@eecs.umich.edu cmd = MemCmd::LoadLockedReq; 3905894Sgblack@eecs.umich.edu } else { 3915894Sgblack@eecs.umich.edu cmd = MemCmd::WriteReq; 3926102Sgblack@eecs.umich.edu if (req->isLLSC()) { 3935894Sgblack@eecs.umich.edu cmd = MemCmd::StoreCondReq; 3945894Sgblack@eecs.umich.edu } else if (req->isSwap()) { 3955894Sgblack@eecs.umich.edu cmd = MemCmd::SwapReq; 3965894Sgblack@eecs.umich.edu } 3975894Sgblack@eecs.umich.edu } 3985894Sgblack@eecs.umich.edu pkt = new Packet(req, cmd, Packet::Broadcast); 3995894Sgblack@eecs.umich.edu} 4005894Sgblack@eecs.umich.edu 4015894Sgblack@eecs.umich.eduvoid 4025894Sgblack@eecs.umich.eduTimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2, 4035894Sgblack@eecs.umich.edu RequestPtr req1, RequestPtr req2, RequestPtr req, 4045894Sgblack@eecs.umich.edu uint8_t *data, bool read) 4055894Sgblack@eecs.umich.edu{ 4065894Sgblack@eecs.umich.edu pkt1 = pkt2 = NULL; 4075894Sgblack@eecs.umich.edu 4085744Sgblack@eecs.umich.edu assert(!req1->isMmapedIpr() && !req2->isMmapedIpr()); 4095744Sgblack@eecs.umich.edu 4105894Sgblack@eecs.umich.edu if (req->getFlags().isSet(Request::NO_ACCESS)) { 4115894Sgblack@eecs.umich.edu buildPacket(pkt1, req, read); 4125894Sgblack@eecs.umich.edu return; 4135894Sgblack@eecs.umich.edu } 4145894Sgblack@eecs.umich.edu 4155894Sgblack@eecs.umich.edu buildPacket(pkt1, req1, read); 4165894Sgblack@eecs.umich.edu buildPacket(pkt2, req2, read); 4175894Sgblack@eecs.umich.edu 4185744Sgblack@eecs.umich.edu req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags()); 4195744Sgblack@eecs.umich.edu PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand(), 4205744Sgblack@eecs.umich.edu Packet::Broadcast); 4215744Sgblack@eecs.umich.edu 4225744Sgblack@eecs.umich.edu pkt->dataDynamic<uint8_t>(data); 4235744Sgblack@eecs.umich.edu pkt1->dataStatic<uint8_t>(data); 4245744Sgblack@eecs.umich.edu pkt2->dataStatic<uint8_t>(data + req1->getSize()); 4255744Sgblack@eecs.umich.edu 4265744Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = new SplitMainSenderState; 4275744Sgblack@eecs.umich.edu pkt->senderState = main_send_state; 4285744Sgblack@eecs.umich.edu main_send_state->fragments[0] = pkt1; 4295744Sgblack@eecs.umich.edu main_send_state->fragments[1] = pkt2; 4305744Sgblack@eecs.umich.edu main_send_state->outstanding = 2; 4315744Sgblack@eecs.umich.edu pkt1->senderState = new SplitFragmentSenderState(pkt, 0); 4325744Sgblack@eecs.umich.edu pkt2->senderState = new SplitFragmentSenderState(pkt, 1); 4335744Sgblack@eecs.umich.edu} 4345744Sgblack@eecs.umich.edu 4352623SN/Atemplate <class T> 4362623SN/AFault 4372623SN/ATimingSimpleCPU::read(Addr addr, T &data, unsigned flags) 4382623SN/A{ 4395728Sgblack@eecs.umich.edu Fault fault; 4405728Sgblack@eecs.umich.edu const int asid = 0; 4416221Snate@binkert.org const ThreadID tid = 0; 4425728Sgblack@eecs.umich.edu const Addr pc = thread->readPC(); 4436227Snate@binkert.org unsigned block_size = dcachePort.peerBlockSize(); 4445728Sgblack@eecs.umich.edu int data_size = sizeof(T); 4452623SN/A 4465744Sgblack@eecs.umich.edu RequestPtr req = new Request(asid, addr, data_size, 4476221Snate@binkert.org flags, pc, _cpuId, tid); 4485728Sgblack@eecs.umich.edu 4495744Sgblack@eecs.umich.edu Addr split_addr = roundDown(addr + data_size - 1, block_size); 4505744Sgblack@eecs.umich.edu assert(split_addr <= addr || split_addr - addr < block_size); 4515728Sgblack@eecs.umich.edu 4525894Sgblack@eecs.umich.edu 4535894Sgblack@eecs.umich.edu _status = DTBWaitResponse; 4545744Sgblack@eecs.umich.edu if (split_addr > addr) { 4555894Sgblack@eecs.umich.edu RequestPtr req1, req2; 4566102Sgblack@eecs.umich.edu assert(!req->isLLSC() && !req->isSwap()); 4575894Sgblack@eecs.umich.edu req->splitOnVaddr(split_addr, req1, req2); 4585894Sgblack@eecs.umich.edu 4595894Sgblack@eecs.umich.edu typedef SplitDataTranslation::WholeTranslationState WholeState; 4605894Sgblack@eecs.umich.edu WholeState *state = new WholeState(req1, req2, req, 4616023Snate@binkert.org (uint8_t *)(new T), BaseTLB::Read); 4625894Sgblack@eecs.umich.edu thread->dtb->translateTiming(req1, tc, 4636023Snate@binkert.org new SplitDataTranslation(this, 0, state), BaseTLB::Read); 4645894Sgblack@eecs.umich.edu thread->dtb->translateTiming(req2, tc, 4656023Snate@binkert.org new SplitDataTranslation(this, 1, state), BaseTLB::Read); 4665744Sgblack@eecs.umich.edu } else { 4676023Snate@binkert.org DataTranslation *translation = 4686023Snate@binkert.org new DataTranslation(this, (uint8_t *)(new T), NULL, BaseTLB::Read); 4696023Snate@binkert.org thread->dtb->translateTiming(req, tc, translation, BaseTLB::Read); 4702623SN/A } 4712623SN/A 4725408Sgblack@eecs.umich.edu if (traceData) { 4735408Sgblack@eecs.umich.edu traceData->setData(data); 4745728Sgblack@eecs.umich.edu traceData->setAddr(addr); 4755408Sgblack@eecs.umich.edu } 4765728Sgblack@eecs.umich.edu 4775728Sgblack@eecs.umich.edu // This will need a new way to tell if it has a dcache attached. 4785728Sgblack@eecs.umich.edu if (req->isUncacheable()) 4795728Sgblack@eecs.umich.edu recordEvent("Uncached Read"); 4805728Sgblack@eecs.umich.edu 4815728Sgblack@eecs.umich.edu return NoFault; 4822623SN/A} 4832623SN/A 4842623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS 4852623SN/A 4862623SN/Atemplate 4872623SN/AFault 4884040Ssaidi@eecs.umich.eduTimingSimpleCPU::read(Addr addr, Twin64_t &data, unsigned flags); 4894040Ssaidi@eecs.umich.edu 4904040Ssaidi@eecs.umich.edutemplate 4914040Ssaidi@eecs.umich.eduFault 4924115Ssaidi@eecs.umich.eduTimingSimpleCPU::read(Addr addr, Twin32_t &data, unsigned flags); 4934115Ssaidi@eecs.umich.edu 4944115Ssaidi@eecs.umich.edutemplate 4954115Ssaidi@eecs.umich.eduFault 4962623SN/ATimingSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags); 4972623SN/A 4982623SN/Atemplate 4992623SN/AFault 5002623SN/ATimingSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags); 5012623SN/A 5022623SN/Atemplate 5032623SN/AFault 5042623SN/ATimingSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags); 5052623SN/A 5062623SN/Atemplate 5072623SN/AFault 5082623SN/ATimingSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags); 5092623SN/A 5102623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS 5112623SN/A 5122623SN/Atemplate<> 5132623SN/AFault 5142623SN/ATimingSimpleCPU::read(Addr addr, double &data, unsigned flags) 5152623SN/A{ 5162623SN/A return read(addr, *(uint64_t*)&data, flags); 5172623SN/A} 5182623SN/A 5192623SN/Atemplate<> 5202623SN/AFault 5212623SN/ATimingSimpleCPU::read(Addr addr, float &data, unsigned flags) 5222623SN/A{ 5232623SN/A return read(addr, *(uint32_t*)&data, flags); 5242623SN/A} 5252623SN/A 5262623SN/A 5272623SN/Atemplate<> 5282623SN/AFault 5292623SN/ATimingSimpleCPU::read(Addr addr, int32_t &data, unsigned flags) 5302623SN/A{ 5312623SN/A return read(addr, (uint32_t&)data, flags); 5322623SN/A} 5332623SN/A 5345728Sgblack@eecs.umich.edubool 5355728Sgblack@eecs.umich.eduTimingSimpleCPU::handleWritePacket() 5365728Sgblack@eecs.umich.edu{ 5375728Sgblack@eecs.umich.edu RequestPtr req = dcache_pkt->req; 5385728Sgblack@eecs.umich.edu if (req->isMmapedIpr()) { 5395728Sgblack@eecs.umich.edu Tick delay; 5405728Sgblack@eecs.umich.edu delay = TheISA::handleIprWrite(thread->getTC(), dcache_pkt); 5415728Sgblack@eecs.umich.edu new IprEvent(dcache_pkt, this, nextCycle(curTick + delay)); 5425728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 5435728Sgblack@eecs.umich.edu dcache_pkt = NULL; 5445728Sgblack@eecs.umich.edu } else if (!dcachePort.sendTiming(dcache_pkt)) { 5455728Sgblack@eecs.umich.edu _status = DcacheRetry; 5465728Sgblack@eecs.umich.edu } else { 5475728Sgblack@eecs.umich.edu _status = DcacheWaitResponse; 5485728Sgblack@eecs.umich.edu // memory system takes ownership of packet 5495728Sgblack@eecs.umich.edu dcache_pkt = NULL; 5505728Sgblack@eecs.umich.edu } 5515728Sgblack@eecs.umich.edu return dcache_pkt == NULL; 5525728Sgblack@eecs.umich.edu} 5532623SN/A 5542623SN/Atemplate <class T> 5552623SN/AFault 5562623SN/ATimingSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res) 5572623SN/A{ 5585728Sgblack@eecs.umich.edu const int asid = 0; 5596221Snate@binkert.org const ThreadID tid = 0; 5605728Sgblack@eecs.umich.edu const Addr pc = thread->readPC(); 5616227Snate@binkert.org unsigned block_size = dcachePort.peerBlockSize(); 5625728Sgblack@eecs.umich.edu int data_size = sizeof(T); 5633169Sstever@eecs.umich.edu 5645744Sgblack@eecs.umich.edu RequestPtr req = new Request(asid, addr, data_size, 5656221Snate@binkert.org flags, pc, _cpuId, tid); 5665728Sgblack@eecs.umich.edu 5675744Sgblack@eecs.umich.edu Addr split_addr = roundDown(addr + data_size - 1, block_size); 5685744Sgblack@eecs.umich.edu assert(split_addr <= addr || split_addr - addr < block_size); 5695728Sgblack@eecs.umich.edu 5705894Sgblack@eecs.umich.edu T *dataP = new T; 5716012Ssteve.reinhardt@amd.com *dataP = TheISA::htog(data); 5725894Sgblack@eecs.umich.edu _status = DTBWaitResponse; 5735744Sgblack@eecs.umich.edu if (split_addr > addr) { 5745894Sgblack@eecs.umich.edu RequestPtr req1, req2; 5756102Sgblack@eecs.umich.edu assert(!req->isLLSC() && !req->isSwap()); 5765894Sgblack@eecs.umich.edu req->splitOnVaddr(split_addr, req1, req2); 5775894Sgblack@eecs.umich.edu 5785894Sgblack@eecs.umich.edu typedef SplitDataTranslation::WholeTranslationState WholeState; 5795894Sgblack@eecs.umich.edu WholeState *state = new WholeState(req1, req2, req, 5806023Snate@binkert.org (uint8_t *)dataP, BaseTLB::Write); 5815894Sgblack@eecs.umich.edu thread->dtb->translateTiming(req1, tc, 5826023Snate@binkert.org new SplitDataTranslation(this, 0, state), BaseTLB::Write); 5835894Sgblack@eecs.umich.edu thread->dtb->translateTiming(req2, tc, 5846023Snate@binkert.org new SplitDataTranslation(this, 1, state), BaseTLB::Write); 5855744Sgblack@eecs.umich.edu } else { 5866023Snate@binkert.org DataTranslation *translation = 5876023Snate@binkert.org new DataTranslation(this, (uint8_t *)dataP, res, BaseTLB::Write); 5886023Snate@binkert.org thread->dtb->translateTiming(req, tc, translation, BaseTLB::Write); 5892623SN/A } 5902623SN/A 5915408Sgblack@eecs.umich.edu if (traceData) { 5925728Sgblack@eecs.umich.edu traceData->setAddr(req->getVaddr()); 5935408Sgblack@eecs.umich.edu traceData->setData(data); 5945408Sgblack@eecs.umich.edu } 5952623SN/A 5965728Sgblack@eecs.umich.edu // This will need a new way to tell if it's hooked up to a cache or not. 5975728Sgblack@eecs.umich.edu if (req->isUncacheable()) 5985728Sgblack@eecs.umich.edu recordEvent("Uncached Write"); 5995728Sgblack@eecs.umich.edu 6002623SN/A // If the write needs to have a fault on the access, consider calling 6012623SN/A // changeStatus() and changing it to "bad addr write" or something. 6025728Sgblack@eecs.umich.edu return NoFault; 6032623SN/A} 6042623SN/A 6052623SN/A 6062623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS 6072623SN/Atemplate 6082623SN/AFault 6094224Sgblack@eecs.umich.eduTimingSimpleCPU::write(Twin32_t data, Addr addr, 6104224Sgblack@eecs.umich.edu unsigned flags, uint64_t *res); 6114224Sgblack@eecs.umich.edu 6124224Sgblack@eecs.umich.edutemplate 6134224Sgblack@eecs.umich.eduFault 6144224Sgblack@eecs.umich.eduTimingSimpleCPU::write(Twin64_t data, Addr addr, 6154224Sgblack@eecs.umich.edu unsigned flags, uint64_t *res); 6164224Sgblack@eecs.umich.edu 6174224Sgblack@eecs.umich.edutemplate 6184224Sgblack@eecs.umich.eduFault 6192623SN/ATimingSimpleCPU::write(uint64_t data, Addr addr, 6202623SN/A unsigned flags, uint64_t *res); 6212623SN/A 6222623SN/Atemplate 6232623SN/AFault 6242623SN/ATimingSimpleCPU::write(uint32_t data, Addr addr, 6252623SN/A unsigned flags, uint64_t *res); 6262623SN/A 6272623SN/Atemplate 6282623SN/AFault 6292623SN/ATimingSimpleCPU::write(uint16_t data, Addr addr, 6302623SN/A unsigned flags, uint64_t *res); 6312623SN/A 6322623SN/Atemplate 6332623SN/AFault 6342623SN/ATimingSimpleCPU::write(uint8_t data, Addr addr, 6352623SN/A unsigned flags, uint64_t *res); 6362623SN/A 6372623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS 6382623SN/A 6392623SN/Atemplate<> 6402623SN/AFault 6412623SN/ATimingSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res) 6422623SN/A{ 6432623SN/A return write(*(uint64_t*)&data, addr, flags, res); 6442623SN/A} 6452623SN/A 6462623SN/Atemplate<> 6472623SN/AFault 6482623SN/ATimingSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res) 6492623SN/A{ 6502623SN/A return write(*(uint32_t*)&data, addr, flags, res); 6512623SN/A} 6522623SN/A 6532623SN/A 6542623SN/Atemplate<> 6552623SN/AFault 6562623SN/ATimingSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res) 6572623SN/A{ 6582623SN/A return write((uint32_t)data, addr, flags, res); 6592623SN/A} 6602623SN/A 6612623SN/A 6622623SN/Avoid 6632623SN/ATimingSimpleCPU::fetch() 6642623SN/A{ 6655221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "Fetch\n"); 6665221Ssaidi@eecs.umich.edu 6673387Sgblack@eecs.umich.edu if (!curStaticInst || !curStaticInst->isDelayedCommit()) 6683387Sgblack@eecs.umich.edu checkForInterrupts(); 6692631SN/A 6705348Ssaidi@eecs.umich.edu checkPcEventQueue(); 6715348Ssaidi@eecs.umich.edu 6725669Sgblack@eecs.umich.edu bool fromRom = isRomMicroPC(thread->readMicroPC()); 6732623SN/A 6745914Sgblack@eecs.umich.edu if (!fromRom && !curMacroStaticInst) { 6755669Sgblack@eecs.umich.edu Request *ifetch_req = new Request(); 6765712Shsul@eecs.umich.edu ifetch_req->setThreadContext(_cpuId, /* thread ID */ 0); 6775894Sgblack@eecs.umich.edu setupFetchRequest(ifetch_req); 6786023Snate@binkert.org thread->itb->translateTiming(ifetch_req, tc, &fetchTranslation, 6796023Snate@binkert.org BaseTLB::Execute); 6802623SN/A } else { 6815669Sgblack@eecs.umich.edu _status = IcacheWaitResponse; 6825669Sgblack@eecs.umich.edu completeIfetch(NULL); 6835894Sgblack@eecs.umich.edu 6845894Sgblack@eecs.umich.edu numCycles += tickToCycles(curTick - previousTick); 6855894Sgblack@eecs.umich.edu previousTick = curTick; 6865894Sgblack@eecs.umich.edu } 6875894Sgblack@eecs.umich.edu} 6885894Sgblack@eecs.umich.edu 6895894Sgblack@eecs.umich.edu 6905894Sgblack@eecs.umich.eduvoid 6915894Sgblack@eecs.umich.eduTimingSimpleCPU::sendFetch(Fault fault, RequestPtr req, ThreadContext *tc) 6925894Sgblack@eecs.umich.edu{ 6935894Sgblack@eecs.umich.edu if (fault == NoFault) { 6945894Sgblack@eecs.umich.edu ifetch_pkt = new Packet(req, MemCmd::ReadReq, Packet::Broadcast); 6955894Sgblack@eecs.umich.edu ifetch_pkt->dataStatic(&inst); 6965894Sgblack@eecs.umich.edu 6975894Sgblack@eecs.umich.edu if (!icachePort.sendTiming(ifetch_pkt)) { 6985894Sgblack@eecs.umich.edu // Need to wait for retry 6995894Sgblack@eecs.umich.edu _status = IcacheRetry; 7005894Sgblack@eecs.umich.edu } else { 7015894Sgblack@eecs.umich.edu // Need to wait for cache to respond 7025894Sgblack@eecs.umich.edu _status = IcacheWaitResponse; 7035894Sgblack@eecs.umich.edu // ownership of packet transferred to memory system 7045894Sgblack@eecs.umich.edu ifetch_pkt = NULL; 7055894Sgblack@eecs.umich.edu } 7065894Sgblack@eecs.umich.edu } else { 7075894Sgblack@eecs.umich.edu delete req; 7085894Sgblack@eecs.umich.edu // fetch fault: advance directly to next instruction (fault handler) 7095894Sgblack@eecs.umich.edu advanceInst(fault); 7102623SN/A } 7113222Sktlim@umich.edu 7125099Ssaidi@eecs.umich.edu numCycles += tickToCycles(curTick - previousTick); 7133222Sktlim@umich.edu previousTick = curTick; 7142623SN/A} 7152623SN/A 7162623SN/A 7172623SN/Avoid 7182644Sstever@eecs.umich.eduTimingSimpleCPU::advanceInst(Fault fault) 7192623SN/A{ 7205726Sgblack@eecs.umich.edu if (fault != NoFault || !stayAtPC) 7215726Sgblack@eecs.umich.edu advancePC(fault); 7222623SN/A 7232631SN/A if (_status == Running) { 7242631SN/A // kick off fetch of next instruction... callback from icache 7252631SN/A // response will cause that instruction to be executed, 7262631SN/A // keeping the CPU running. 7272631SN/A fetch(); 7282631SN/A } 7292623SN/A} 7302623SN/A 7312623SN/A 7322623SN/Avoid 7333349Sbinkertn@umich.eduTimingSimpleCPU::completeIfetch(PacketPtr pkt) 7342623SN/A{ 7355221Ssaidi@eecs.umich.edu DPRINTF(SimpleCPU, "Complete ICache Fetch\n"); 7365221Ssaidi@eecs.umich.edu 7372623SN/A // received a response from the icache: execute the received 7382623SN/A // instruction 7395669Sgblack@eecs.umich.edu 7405669Sgblack@eecs.umich.edu assert(!pkt || !pkt->isError()); 7412623SN/A assert(_status == IcacheWaitResponse); 7422798Sktlim@umich.edu 7432623SN/A _status = Running; 7442644Sstever@eecs.umich.edu 7455099Ssaidi@eecs.umich.edu numCycles += tickToCycles(curTick - previousTick); 7463222Sktlim@umich.edu previousTick = curTick; 7473222Sktlim@umich.edu 7482839Sktlim@umich.edu if (getState() == SimObject::Draining) { 7495669Sgblack@eecs.umich.edu if (pkt) { 7505669Sgblack@eecs.umich.edu delete pkt->req; 7515669Sgblack@eecs.umich.edu delete pkt; 7525669Sgblack@eecs.umich.edu } 7533658Sktlim@umich.edu 7542839Sktlim@umich.edu completeDrain(); 7552798Sktlim@umich.edu return; 7562798Sktlim@umich.edu } 7572798Sktlim@umich.edu 7582623SN/A preExecute(); 7595726Sgblack@eecs.umich.edu if (curStaticInst && 7605726Sgblack@eecs.umich.edu curStaticInst->isMemRef() && !curStaticInst->isDataPrefetch()) { 7612623SN/A // load or store: just send to dcache 7622623SN/A Fault fault = curStaticInst->initiateAcc(this, traceData); 7633170Sstever@eecs.umich.edu if (_status != Running) { 7643170Sstever@eecs.umich.edu // instruction will complete in dcache response callback 7655894Sgblack@eecs.umich.edu assert(_status == DcacheWaitResponse || 7665894Sgblack@eecs.umich.edu _status == DcacheRetry || DTBWaitResponse); 7673170Sstever@eecs.umich.edu assert(fault == NoFault); 7682644Sstever@eecs.umich.edu } else { 7695894Sgblack@eecs.umich.edu if (fault != NoFault && traceData) { 7705001Sgblack@eecs.umich.edu // If there was a fault, we shouldn't trace this instruction. 7715001Sgblack@eecs.umich.edu delete traceData; 7725001Sgblack@eecs.umich.edu traceData = NULL; 7733170Sstever@eecs.umich.edu } 7744998Sgblack@eecs.umich.edu 7752644Sstever@eecs.umich.edu postExecute(); 7765103Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 7775103Ssaidi@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 7785103Ssaidi@eecs.umich.edu curStaticInst->isFirstMicroop())) 7795103Ssaidi@eecs.umich.edu instCnt++; 7802644Sstever@eecs.umich.edu advanceInst(fault); 7812644Sstever@eecs.umich.edu } 7825726Sgblack@eecs.umich.edu } else if (curStaticInst) { 7832623SN/A // non-memory instruction: execute completely now 7842623SN/A Fault fault = curStaticInst->execute(this, traceData); 7854998Sgblack@eecs.umich.edu 7864998Sgblack@eecs.umich.edu // keep an instruction count 7874998Sgblack@eecs.umich.edu if (fault == NoFault) 7884998Sgblack@eecs.umich.edu countInst(); 7895001Sgblack@eecs.umich.edu else if (traceData) { 7905001Sgblack@eecs.umich.edu // If there was a fault, we shouldn't trace this instruction. 7915001Sgblack@eecs.umich.edu delete traceData; 7925001Sgblack@eecs.umich.edu traceData = NULL; 7935001Sgblack@eecs.umich.edu } 7944998Sgblack@eecs.umich.edu 7952644Sstever@eecs.umich.edu postExecute(); 7965103Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 7975103Ssaidi@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 7985103Ssaidi@eecs.umich.edu curStaticInst->isFirstMicroop())) 7995103Ssaidi@eecs.umich.edu instCnt++; 8002644Sstever@eecs.umich.edu advanceInst(fault); 8015726Sgblack@eecs.umich.edu } else { 8025726Sgblack@eecs.umich.edu advanceInst(NoFault); 8032623SN/A } 8043658Sktlim@umich.edu 8055669Sgblack@eecs.umich.edu if (pkt) { 8065669Sgblack@eecs.umich.edu delete pkt->req; 8075669Sgblack@eecs.umich.edu delete pkt; 8085669Sgblack@eecs.umich.edu } 8092623SN/A} 8102623SN/A 8112948Ssaidi@eecs.umich.eduvoid 8122948Ssaidi@eecs.umich.eduTimingSimpleCPU::IcachePort::ITickEvent::process() 8132948Ssaidi@eecs.umich.edu{ 8142948Ssaidi@eecs.umich.edu cpu->completeIfetch(pkt); 8152948Ssaidi@eecs.umich.edu} 8162623SN/A 8172623SN/Abool 8183349Sbinkertn@umich.eduTimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt) 8192623SN/A{ 8204986Ssaidi@eecs.umich.edu if (pkt->isResponse() && !pkt->wasNacked()) { 8213310Srdreslin@umich.edu // delay processing of returned data until next CPU clock edge 8224584Ssaidi@eecs.umich.edu Tick next_tick = cpu->nextCycle(curTick); 8232948Ssaidi@eecs.umich.edu 8243495Sktlim@umich.edu if (next_tick == curTick) 8253310Srdreslin@umich.edu cpu->completeIfetch(pkt); 8263310Srdreslin@umich.edu else 8273495Sktlim@umich.edu tickEvent.schedule(pkt, next_tick); 8282948Ssaidi@eecs.umich.edu 8293310Srdreslin@umich.edu return true; 8303310Srdreslin@umich.edu } 8314870Sstever@eecs.umich.edu else if (pkt->wasNacked()) { 8324433Ssaidi@eecs.umich.edu assert(cpu->_status == IcacheWaitResponse); 8334433Ssaidi@eecs.umich.edu pkt->reinitNacked(); 8344433Ssaidi@eecs.umich.edu if (!sendTiming(pkt)) { 8354433Ssaidi@eecs.umich.edu cpu->_status = IcacheRetry; 8364433Ssaidi@eecs.umich.edu cpu->ifetch_pkt = pkt; 8374433Ssaidi@eecs.umich.edu } 8383310Srdreslin@umich.edu } 8394433Ssaidi@eecs.umich.edu //Snooping a Coherence Request, do nothing 8404433Ssaidi@eecs.umich.edu return true; 8412623SN/A} 8422623SN/A 8432657Ssaidi@eecs.umich.eduvoid 8442623SN/ATimingSimpleCPU::IcachePort::recvRetry() 8452623SN/A{ 8462623SN/A // we shouldn't get a retry unless we have a packet that we're 8472623SN/A // waiting to transmit 8482623SN/A assert(cpu->ifetch_pkt != NULL); 8492623SN/A assert(cpu->_status == IcacheRetry); 8503349Sbinkertn@umich.edu PacketPtr tmp = cpu->ifetch_pkt; 8512657Ssaidi@eecs.umich.edu if (sendTiming(tmp)) { 8522657Ssaidi@eecs.umich.edu cpu->_status = IcacheWaitResponse; 8532657Ssaidi@eecs.umich.edu cpu->ifetch_pkt = NULL; 8542657Ssaidi@eecs.umich.edu } 8552623SN/A} 8562623SN/A 8572623SN/Avoid 8583349Sbinkertn@umich.eduTimingSimpleCPU::completeDataAccess(PacketPtr pkt) 8592623SN/A{ 8602623SN/A // received a response from the dcache: complete the load or store 8612623SN/A // instruction 8624870Sstever@eecs.umich.edu assert(!pkt->isError()); 8632623SN/A 8645099Ssaidi@eecs.umich.edu numCycles += tickToCycles(curTick - previousTick); 8653222Sktlim@umich.edu previousTick = curTick; 8663184Srdreslin@umich.edu 8675728Sgblack@eecs.umich.edu if (pkt->senderState) { 8685728Sgblack@eecs.umich.edu SplitFragmentSenderState * send_state = 8695728Sgblack@eecs.umich.edu dynamic_cast<SplitFragmentSenderState *>(pkt->senderState); 8705728Sgblack@eecs.umich.edu assert(send_state); 8715728Sgblack@eecs.umich.edu delete pkt->req; 8725728Sgblack@eecs.umich.edu delete pkt; 8735728Sgblack@eecs.umich.edu PacketPtr big_pkt = send_state->bigPkt; 8745728Sgblack@eecs.umich.edu delete send_state; 8755728Sgblack@eecs.umich.edu 8765728Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = 8775728Sgblack@eecs.umich.edu dynamic_cast<SplitMainSenderState *>(big_pkt->senderState); 8785728Sgblack@eecs.umich.edu assert(main_send_state); 8795728Sgblack@eecs.umich.edu // Record the fact that this packet is no longer outstanding. 8805728Sgblack@eecs.umich.edu assert(main_send_state->outstanding != 0); 8815728Sgblack@eecs.umich.edu main_send_state->outstanding--; 8825728Sgblack@eecs.umich.edu 8835728Sgblack@eecs.umich.edu if (main_send_state->outstanding) { 8845728Sgblack@eecs.umich.edu return; 8855728Sgblack@eecs.umich.edu } else { 8865728Sgblack@eecs.umich.edu delete main_send_state; 8875728Sgblack@eecs.umich.edu big_pkt->senderState = NULL; 8885728Sgblack@eecs.umich.edu pkt = big_pkt; 8895728Sgblack@eecs.umich.edu } 8905728Sgblack@eecs.umich.edu } 8915728Sgblack@eecs.umich.edu 8925894Sgblack@eecs.umich.edu assert(_status == DcacheWaitResponse || _status == DTBWaitResponse); 8935728Sgblack@eecs.umich.edu _status = Running; 8945728Sgblack@eecs.umich.edu 8952623SN/A Fault fault = curStaticInst->completeAcc(pkt, this, traceData); 8962623SN/A 8974998Sgblack@eecs.umich.edu // keep an instruction count 8984998Sgblack@eecs.umich.edu if (fault == NoFault) 8994998Sgblack@eecs.umich.edu countInst(); 9005001Sgblack@eecs.umich.edu else if (traceData) { 9015001Sgblack@eecs.umich.edu // If there was a fault, we shouldn't trace this instruction. 9025001Sgblack@eecs.umich.edu delete traceData; 9035001Sgblack@eecs.umich.edu traceData = NULL; 9045001Sgblack@eecs.umich.edu } 9054998Sgblack@eecs.umich.edu 9065507Sstever@gmail.com // the locked flag may be cleared on the response packet, so check 9075507Sstever@gmail.com // pkt->req and not pkt to see if it was a load-locked 9086102Sgblack@eecs.umich.edu if (pkt->isRead() && pkt->req->isLLSC()) { 9093170Sstever@eecs.umich.edu TheISA::handleLockedRead(thread, pkt->req); 9103170Sstever@eecs.umich.edu } 9113170Sstever@eecs.umich.edu 9122644Sstever@eecs.umich.edu delete pkt->req; 9132644Sstever@eecs.umich.edu delete pkt; 9142644Sstever@eecs.umich.edu 9153184Srdreslin@umich.edu postExecute(); 9163227Sktlim@umich.edu 9173201Shsul@eecs.umich.edu if (getState() == SimObject::Draining) { 9183201Shsul@eecs.umich.edu advancePC(fault); 9193201Shsul@eecs.umich.edu completeDrain(); 9203201Shsul@eecs.umich.edu 9213201Shsul@eecs.umich.edu return; 9223201Shsul@eecs.umich.edu } 9233201Shsul@eecs.umich.edu 9242644Sstever@eecs.umich.edu advanceInst(fault); 9252623SN/A} 9262623SN/A 9272623SN/A 9282798Sktlim@umich.eduvoid 9292839Sktlim@umich.eduTimingSimpleCPU::completeDrain() 9302798Sktlim@umich.edu{ 9312839Sktlim@umich.edu DPRINTF(Config, "Done draining\n"); 9322901Ssaidi@eecs.umich.edu changeState(SimObject::Drained); 9332839Sktlim@umich.edu drainEvent->process(); 9342798Sktlim@umich.edu} 9352623SN/A 9364192Sktlim@umich.eduvoid 9374192Sktlim@umich.eduTimingSimpleCPU::DcachePort::setPeer(Port *port) 9384192Sktlim@umich.edu{ 9394192Sktlim@umich.edu Port::setPeer(port); 9404192Sktlim@umich.edu 9414192Sktlim@umich.edu#if FULL_SYSTEM 9424192Sktlim@umich.edu // Update the ThreadContext's memory ports (Functional/Virtual 9434192Sktlim@umich.edu // Ports) 9445497Ssaidi@eecs.umich.edu cpu->tcBase()->connectMemPorts(cpu->tcBase()); 9454192Sktlim@umich.edu#endif 9464192Sktlim@umich.edu} 9474192Sktlim@umich.edu 9482623SN/Abool 9493349Sbinkertn@umich.eduTimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt) 9502623SN/A{ 9514986Ssaidi@eecs.umich.edu if (pkt->isResponse() && !pkt->wasNacked()) { 9523310Srdreslin@umich.edu // delay processing of returned data until next CPU clock edge 9534584Ssaidi@eecs.umich.edu Tick next_tick = cpu->nextCycle(curTick); 9542948Ssaidi@eecs.umich.edu 9555728Sgblack@eecs.umich.edu if (next_tick == curTick) { 9563310Srdreslin@umich.edu cpu->completeDataAccess(pkt); 9575728Sgblack@eecs.umich.edu } else { 9583495Sktlim@umich.edu tickEvent.schedule(pkt, next_tick); 9595728Sgblack@eecs.umich.edu } 9602948Ssaidi@eecs.umich.edu 9613310Srdreslin@umich.edu return true; 9623310Srdreslin@umich.edu } 9634870Sstever@eecs.umich.edu else if (pkt->wasNacked()) { 9644433Ssaidi@eecs.umich.edu assert(cpu->_status == DcacheWaitResponse); 9654433Ssaidi@eecs.umich.edu pkt->reinitNacked(); 9664433Ssaidi@eecs.umich.edu if (!sendTiming(pkt)) { 9674433Ssaidi@eecs.umich.edu cpu->_status = DcacheRetry; 9684433Ssaidi@eecs.umich.edu cpu->dcache_pkt = pkt; 9694433Ssaidi@eecs.umich.edu } 9703310Srdreslin@umich.edu } 9714433Ssaidi@eecs.umich.edu //Snooping a Coherence Request, do nothing 9724433Ssaidi@eecs.umich.edu return true; 9732948Ssaidi@eecs.umich.edu} 9742948Ssaidi@eecs.umich.edu 9752948Ssaidi@eecs.umich.eduvoid 9762948Ssaidi@eecs.umich.eduTimingSimpleCPU::DcachePort::DTickEvent::process() 9772948Ssaidi@eecs.umich.edu{ 9782630SN/A cpu->completeDataAccess(pkt); 9792623SN/A} 9802623SN/A 9812657Ssaidi@eecs.umich.eduvoid 9822623SN/ATimingSimpleCPU::DcachePort::recvRetry() 9832623SN/A{ 9842623SN/A // we shouldn't get a retry unless we have a packet that we're 9852623SN/A // waiting to transmit 9862623SN/A assert(cpu->dcache_pkt != NULL); 9872623SN/A assert(cpu->_status == DcacheRetry); 9883349Sbinkertn@umich.edu PacketPtr tmp = cpu->dcache_pkt; 9895728Sgblack@eecs.umich.edu if (tmp->senderState) { 9905728Sgblack@eecs.umich.edu // This is a packet from a split access. 9915728Sgblack@eecs.umich.edu SplitFragmentSenderState * send_state = 9925728Sgblack@eecs.umich.edu dynamic_cast<SplitFragmentSenderState *>(tmp->senderState); 9935728Sgblack@eecs.umich.edu assert(send_state); 9945728Sgblack@eecs.umich.edu PacketPtr big_pkt = send_state->bigPkt; 9955728Sgblack@eecs.umich.edu 9965728Sgblack@eecs.umich.edu SplitMainSenderState * main_send_state = 9975728Sgblack@eecs.umich.edu dynamic_cast<SplitMainSenderState *>(big_pkt->senderState); 9985728Sgblack@eecs.umich.edu assert(main_send_state); 9995728Sgblack@eecs.umich.edu 10005728Sgblack@eecs.umich.edu if (sendTiming(tmp)) { 10015728Sgblack@eecs.umich.edu // If we were able to send without retrying, record that fact 10025728Sgblack@eecs.umich.edu // and try sending the other fragment. 10035728Sgblack@eecs.umich.edu send_state->clearFromParent(); 10045728Sgblack@eecs.umich.edu int other_index = main_send_state->getPendingFragment(); 10055728Sgblack@eecs.umich.edu if (other_index > 0) { 10065728Sgblack@eecs.umich.edu tmp = main_send_state->fragments[other_index]; 10075728Sgblack@eecs.umich.edu cpu->dcache_pkt = tmp; 10085728Sgblack@eecs.umich.edu if ((big_pkt->isRead() && cpu->handleReadPacket(tmp)) || 10095728Sgblack@eecs.umich.edu (big_pkt->isWrite() && cpu->handleWritePacket())) { 10105728Sgblack@eecs.umich.edu main_send_state->fragments[other_index] = NULL; 10115728Sgblack@eecs.umich.edu } 10125728Sgblack@eecs.umich.edu } else { 10135728Sgblack@eecs.umich.edu cpu->_status = DcacheWaitResponse; 10145728Sgblack@eecs.umich.edu // memory system takes ownership of packet 10155728Sgblack@eecs.umich.edu cpu->dcache_pkt = NULL; 10165728Sgblack@eecs.umich.edu } 10175728Sgblack@eecs.umich.edu } 10185728Sgblack@eecs.umich.edu } else if (sendTiming(tmp)) { 10192657Ssaidi@eecs.umich.edu cpu->_status = DcacheWaitResponse; 10203170Sstever@eecs.umich.edu // memory system takes ownership of packet 10212657Ssaidi@eecs.umich.edu cpu->dcache_pkt = NULL; 10222657Ssaidi@eecs.umich.edu } 10232623SN/A} 10242623SN/A 10255606Snate@binkert.orgTimingSimpleCPU::IprEvent::IprEvent(Packet *_pkt, TimingSimpleCPU *_cpu, 10265606Snate@binkert.org Tick t) 10275606Snate@binkert.org : pkt(_pkt), cpu(_cpu) 10285103Ssaidi@eecs.umich.edu{ 10295606Snate@binkert.org cpu->schedule(this, t); 10305103Ssaidi@eecs.umich.edu} 10315103Ssaidi@eecs.umich.edu 10325103Ssaidi@eecs.umich.eduvoid 10335103Ssaidi@eecs.umich.eduTimingSimpleCPU::IprEvent::process() 10345103Ssaidi@eecs.umich.edu{ 10355103Ssaidi@eecs.umich.edu cpu->completeDataAccess(pkt); 10365103Ssaidi@eecs.umich.edu} 10375103Ssaidi@eecs.umich.edu 10385103Ssaidi@eecs.umich.educonst char * 10395336Shines@cs.fsu.eduTimingSimpleCPU::IprEvent::description() const 10405103Ssaidi@eecs.umich.edu{ 10415103Ssaidi@eecs.umich.edu return "Timing Simple CPU Delay IPR event"; 10425103Ssaidi@eecs.umich.edu} 10435103Ssaidi@eecs.umich.edu 10442623SN/A 10455315Sstever@gmail.comvoid 10465315Sstever@gmail.comTimingSimpleCPU::printAddr(Addr a) 10475315Sstever@gmail.com{ 10485315Sstever@gmail.com dcachePort.printAddr(a); 10495315Sstever@gmail.com} 10505315Sstever@gmail.com 10515315Sstever@gmail.com 10522623SN/A//////////////////////////////////////////////////////////////////////// 10532623SN/A// 10542623SN/A// TimingSimpleCPU Simulation Object 10552623SN/A// 10564762Snate@binkert.orgTimingSimpleCPU * 10574762Snate@binkert.orgTimingSimpleCPUParams::create() 10582623SN/A{ 10595529Snate@binkert.org numThreads = 1; 10605529Snate@binkert.org#if !FULL_SYSTEM 10614762Snate@binkert.org if (workload.size() != 1) 10624762Snate@binkert.org panic("only one workload allowed"); 10632623SN/A#endif 10645529Snate@binkert.org return new TimingSimpleCPU(this); 10652623SN/A} 1066