atomic.cc revision 8931
12623SN/A/* 28926Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited 38926Sandreas.hansson@arm.com * All rights reserved. 48926Sandreas.hansson@arm.com * 58926Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68926Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78926Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88926Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98926Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108926Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118926Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128926Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138926Sandreas.hansson@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/atomic.hh" 492623SN/A#include "cpu/exetrace.hh" 508232Snate@binkert.org#include "debug/ExecFaulting.hh" 518232Snate@binkert.org#include "debug/SimpleCPU.hh" 523348Sbinkertn@umich.edu#include "mem/packet.hh" 533348Sbinkertn@umich.edu#include "mem/packet_access.hh" 548926Sandreas.hansson@arm.com#include "mem/physical.hh" 554762Snate@binkert.org#include "params/AtomicSimpleCPU.hh" 567678Sgblack@eecs.umich.edu#include "sim/faults.hh" 572901Ssaidi@eecs.umich.edu#include "sim/system.hh" 588779Sgblack@eecs.umich.edu#include "sim/full_system.hh" 592623SN/A 602623SN/Ausing namespace std; 612623SN/Ausing namespace TheISA; 622623SN/A 632623SN/AAtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c) 645606Snate@binkert.org : Event(CPU_Tick_Pri), cpu(c) 652623SN/A{ 662623SN/A} 672623SN/A 682623SN/A 692623SN/Avoid 702623SN/AAtomicSimpleCPU::TickEvent::process() 712623SN/A{ 722623SN/A cpu->tick(); 732623SN/A} 742623SN/A 752623SN/Aconst char * 765336Shines@cs.fsu.eduAtomicSimpleCPU::TickEvent::description() const 772623SN/A{ 784873Sstever@eecs.umich.edu return "AtomicSimpleCPU tick"; 792623SN/A} 802623SN/A 812623SN/Avoid 822623SN/AAtomicSimpleCPU::init() 832623SN/A{ 842623SN/A BaseCPU::init(); 858921Sandreas.hansson@arm.com 868921Sandreas.hansson@arm.com // Initialise the ThreadContext's memory proxies 878921Sandreas.hansson@arm.com tcBase()->initMemProxies(tcBase()); 888921Sandreas.hansson@arm.com 898779Sgblack@eecs.umich.edu if (FullSystem) { 908779Sgblack@eecs.umich.edu ThreadID size = threadContexts.size(); 918779Sgblack@eecs.umich.edu for (ThreadID i = 0; i < size; ++i) { 928779Sgblack@eecs.umich.edu ThreadContext *tc = threadContexts[i]; 938779Sgblack@eecs.umich.edu // initialize CPU, including PC 948779Sgblack@eecs.umich.edu TheISA::initCPU(tc, tc->contextId()); 958779Sgblack@eecs.umich.edu } 962623SN/A } 978706Sandreas.hansson@arm.com 985714Shsul@eecs.umich.edu // Atomic doesn't do MT right now, so contextId == threadId 995712Shsul@eecs.umich.edu ifetch_req.setThreadContext(_cpuId, 0); // Add thread ID if we add MT 1005712Shsul@eecs.umich.edu data_read_req.setThreadContext(_cpuId, 0); // Add thread ID here too 1015712Shsul@eecs.umich.edu data_write_req.setThreadContext(_cpuId, 0); // Add thread ID here too 1022623SN/A} 1032623SN/A 1045529Snate@binkert.orgAtomicSimpleCPU::AtomicSimpleCPU(AtomicSimpleCPUParams *p) 1056078Sgblack@eecs.umich.edu : BaseSimpleCPU(p), tickEvent(this), width(p->width), locked(false), 1065487Snate@binkert.org simulate_data_stalls(p->simulate_data_stalls), 1075487Snate@binkert.org simulate_inst_stalls(p->simulate_inst_stalls), 1084968Sacolyte@umich.edu icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this), 1098926Sandreas.hansson@arm.com fastmem(p->fastmem) 1102623SN/A{ 1112623SN/A _status = Idle; 1122623SN/A} 1132623SN/A 1142623SN/A 1152623SN/AAtomicSimpleCPU::~AtomicSimpleCPU() 1162623SN/A{ 1176775SBrad.Beckmann@amd.com if (tickEvent.scheduled()) { 1186775SBrad.Beckmann@amd.com deschedule(tickEvent); 1196775SBrad.Beckmann@amd.com } 1202623SN/A} 1212623SN/A 1222623SN/Avoid 1232623SN/AAtomicSimpleCPU::serialize(ostream &os) 1242623SN/A{ 1252915Sktlim@umich.edu SimObject::State so_state = SimObject::getState(); 1262915Sktlim@umich.edu SERIALIZE_ENUM(so_state); 1276078Sgblack@eecs.umich.edu SERIALIZE_SCALAR(locked); 1283145Shsul@eecs.umich.edu BaseSimpleCPU::serialize(os); 1292623SN/A nameOut(os, csprintf("%s.tickEvent", name())); 1302623SN/A tickEvent.serialize(os); 1312623SN/A} 1322623SN/A 1332623SN/Avoid 1342623SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 1352623SN/A{ 1362915Sktlim@umich.edu SimObject::State so_state; 1372915Sktlim@umich.edu UNSERIALIZE_ENUM(so_state); 1386078Sgblack@eecs.umich.edu UNSERIALIZE_SCALAR(locked); 1393145Shsul@eecs.umich.edu BaseSimpleCPU::unserialize(cp, section); 1402915Sktlim@umich.edu tickEvent.unserialize(cp, csprintf("%s.tickEvent", section)); 1412915Sktlim@umich.edu} 1422915Sktlim@umich.edu 1432915Sktlim@umich.eduvoid 1442915Sktlim@umich.eduAtomicSimpleCPU::resume() 1452915Sktlim@umich.edu{ 1465220Ssaidi@eecs.umich.edu if (_status == Idle || _status == SwitchedOut) 1475220Ssaidi@eecs.umich.edu return; 1485220Ssaidi@eecs.umich.edu 1494940Snate@binkert.org DPRINTF(SimpleCPU, "Resume\n"); 1505220Ssaidi@eecs.umich.edu assert(system->getMemoryMode() == Enums::atomic); 1513324Shsul@eecs.umich.edu 1525220Ssaidi@eecs.umich.edu changeState(SimObject::Running); 1535220Ssaidi@eecs.umich.edu if (thread->status() == ThreadContext::Active) { 1545606Snate@binkert.org if (!tickEvent.scheduled()) 1555606Snate@binkert.org schedule(tickEvent, nextCycle()); 1562915Sktlim@umich.edu } 1577897Shestness@cs.utexas.edu system->totalNumInsts = 0; 1582623SN/A} 1592623SN/A 1602623SN/Avoid 1612798Sktlim@umich.eduAtomicSimpleCPU::switchOut() 1622623SN/A{ 1635496Ssaidi@eecs.umich.edu assert(_status == Running || _status == Idle); 1642798Sktlim@umich.edu _status = SwitchedOut; 1652623SN/A 1662798Sktlim@umich.edu tickEvent.squash(); 1672623SN/A} 1682623SN/A 1692623SN/A 1702623SN/Avoid 1712623SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 1722623SN/A{ 1738737Skoansin.tan@gmail.com BaseCPU::takeOverFrom(oldCPU); 1742623SN/A 1752623SN/A assert(!tickEvent.scheduled()); 1762623SN/A 1772680Sktlim@umich.edu // if any of this CPU's ThreadContexts are active, mark the CPU as 1782623SN/A // running and schedule its tick event. 1796221Snate@binkert.org ThreadID size = threadContexts.size(); 1806221Snate@binkert.org for (ThreadID i = 0; i < size; ++i) { 1812680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 1822680Sktlim@umich.edu if (tc->status() == ThreadContext::Active && _status != Running) { 1832623SN/A _status = Running; 1845606Snate@binkert.org schedule(tickEvent, nextCycle()); 1852623SN/A break; 1862623SN/A } 1872623SN/A } 1883512Sktlim@umich.edu if (_status != Running) { 1893512Sktlim@umich.edu _status = Idle; 1903512Sktlim@umich.edu } 1915169Ssaidi@eecs.umich.edu assert(threadContexts.size() == 1); 1925712Shsul@eecs.umich.edu ifetch_req.setThreadContext(_cpuId, 0); // Add thread ID if we add MT 1935712Shsul@eecs.umich.edu data_read_req.setThreadContext(_cpuId, 0); // Add thread ID here too 1945712Shsul@eecs.umich.edu data_write_req.setThreadContext(_cpuId, 0); // Add thread ID here too 1952623SN/A} 1962623SN/A 1972623SN/A 1982623SN/Avoid 1998737Skoansin.tan@gmail.comAtomicSimpleCPU::activateContext(ThreadID thread_num, int delay) 2002623SN/A{ 2014940Snate@binkert.org DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay); 2024940Snate@binkert.org 2032623SN/A assert(thread_num == 0); 2042683Sktlim@umich.edu assert(thread); 2052623SN/A 2062623SN/A assert(_status == Idle); 2072623SN/A assert(!tickEvent.scheduled()); 2082623SN/A 2092623SN/A notIdleFraction++; 2105101Ssaidi@eecs.umich.edu numCycles += tickToCycles(thread->lastActivate - thread->lastSuspend); 2113686Sktlim@umich.edu 2123430Sgblack@eecs.umich.edu //Make sure ticks are still on multiples of cycles 2137823Ssteve.reinhardt@amd.com schedule(tickEvent, nextCycle(curTick() + ticks(delay))); 2142623SN/A _status = Running; 2152623SN/A} 2162623SN/A 2172623SN/A 2182623SN/Avoid 2198737Skoansin.tan@gmail.comAtomicSimpleCPU::suspendContext(ThreadID thread_num) 2202623SN/A{ 2214940Snate@binkert.org DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num); 2224940Snate@binkert.org 2232623SN/A assert(thread_num == 0); 2242683Sktlim@umich.edu assert(thread); 2252623SN/A 2266043Sgblack@eecs.umich.edu if (_status == Idle) 2276043Sgblack@eecs.umich.edu return; 2286043Sgblack@eecs.umich.edu 2292623SN/A assert(_status == Running); 2302626SN/A 2312626SN/A // tick event may not be scheduled if this gets called from inside 2322626SN/A // an instruction's execution, e.g. "quiesce" 2332626SN/A if (tickEvent.scheduled()) 2345606Snate@binkert.org deschedule(tickEvent); 2352623SN/A 2362623SN/A notIdleFraction--; 2372623SN/A _status = Idle; 2382623SN/A} 2392623SN/A 2402623SN/A 2412623SN/AFault 2428444Sgblack@eecs.umich.eduAtomicSimpleCPU::readMem(Addr addr, uint8_t * data, 2438444Sgblack@eecs.umich.edu unsigned size, unsigned flags) 2442623SN/A{ 2453169Sstever@eecs.umich.edu // use the CPU's statically allocated read request and packet objects 2464870Sstever@eecs.umich.edu Request *req = &data_read_req; 2472623SN/A 2482623SN/A if (traceData) { 2492623SN/A traceData->setAddr(addr); 2502623SN/A } 2512623SN/A 2524999Sgblack@eecs.umich.edu //The block size of our peer. 2536227Snate@binkert.org unsigned blockSize = dcachePort.peerBlockSize(); 2544999Sgblack@eecs.umich.edu //The size of the data we're trying to read. 2557520Sgblack@eecs.umich.edu int fullSize = size; 2562623SN/A 2574999Sgblack@eecs.umich.edu //The address of the second part of this access if it needs to be split 2584999Sgblack@eecs.umich.edu //across a cache line boundary. 2597520Sgblack@eecs.umich.edu Addr secondAddr = roundDown(addr + size - 1, blockSize); 2604999Sgblack@eecs.umich.edu 2617520Sgblack@eecs.umich.edu if (secondAddr > addr) 2627520Sgblack@eecs.umich.edu size = secondAddr - addr; 2634999Sgblack@eecs.umich.edu 2644999Sgblack@eecs.umich.edu dcache_latency = 0; 2654999Sgblack@eecs.umich.edu 2667520Sgblack@eecs.umich.edu while (1) { 2678832SAli.Saidi@ARM.com req->setVirt(0, addr, size, flags, dataMasterId(), thread->pcState().instAddr()); 2684999Sgblack@eecs.umich.edu 2694999Sgblack@eecs.umich.edu // translate to physical address 2706023Snate@binkert.org Fault fault = thread->dtb->translateAtomic(req, tc, BaseTLB::Read); 2714999Sgblack@eecs.umich.edu 2724999Sgblack@eecs.umich.edu // Now do the access. 2736623Sgblack@eecs.umich.edu if (fault == NoFault && !req->getFlags().isSet(Request::NO_ACCESS)) { 2744999Sgblack@eecs.umich.edu Packet pkt = Packet(req, 2756102Sgblack@eecs.umich.edu req->isLLSC() ? MemCmd::LoadLockedReq : MemCmd::ReadReq, 2764999Sgblack@eecs.umich.edu Packet::Broadcast); 2777520Sgblack@eecs.umich.edu pkt.dataStatic(data); 2784999Sgblack@eecs.umich.edu 2798105Sgblack@eecs.umich.edu if (req->isMmappedIpr()) 2804999Sgblack@eecs.umich.edu dcache_latency += TheISA::handleIprRead(thread->getTC(), &pkt); 2814999Sgblack@eecs.umich.edu else { 2828931Sandreas.hansson@arm.com if (fastmem && system->isMemAddr(pkt.getAddr())) 2838931Sandreas.hansson@arm.com system->getPhysMem().access(&pkt); 2844999Sgblack@eecs.umich.edu else 2854999Sgblack@eecs.umich.edu dcache_latency += dcachePort.sendAtomic(&pkt); 2864999Sgblack@eecs.umich.edu } 2874999Sgblack@eecs.umich.edu dcache_access = true; 2885012Sgblack@eecs.umich.edu 2894999Sgblack@eecs.umich.edu assert(!pkt.isError()); 2904999Sgblack@eecs.umich.edu 2916102Sgblack@eecs.umich.edu if (req->isLLSC()) { 2924999Sgblack@eecs.umich.edu TheISA::handleLockedRead(thread, req); 2934999Sgblack@eecs.umich.edu } 2944968Sacolyte@umich.edu } 2954986Ssaidi@eecs.umich.edu 2964999Sgblack@eecs.umich.edu //If there's a fault, return it 2976739Sgblack@eecs.umich.edu if (fault != NoFault) { 2986739Sgblack@eecs.umich.edu if (req->isPrefetch()) { 2996739Sgblack@eecs.umich.edu return NoFault; 3006739Sgblack@eecs.umich.edu } else { 3016739Sgblack@eecs.umich.edu return fault; 3026739Sgblack@eecs.umich.edu } 3036739Sgblack@eecs.umich.edu } 3046739Sgblack@eecs.umich.edu 3054999Sgblack@eecs.umich.edu //If we don't need to access a second cache line, stop now. 3064999Sgblack@eecs.umich.edu if (secondAddr <= addr) 3074999Sgblack@eecs.umich.edu { 3086078Sgblack@eecs.umich.edu if (req->isLocked() && fault == NoFault) { 3096078Sgblack@eecs.umich.edu assert(!locked); 3106078Sgblack@eecs.umich.edu locked = true; 3116078Sgblack@eecs.umich.edu } 3124999Sgblack@eecs.umich.edu return fault; 3134968Sacolyte@umich.edu } 3143170Sstever@eecs.umich.edu 3154999Sgblack@eecs.umich.edu /* 3164999Sgblack@eecs.umich.edu * Set up for accessing the second cache line. 3174999Sgblack@eecs.umich.edu */ 3184999Sgblack@eecs.umich.edu 3194999Sgblack@eecs.umich.edu //Move the pointer we're reading into to the correct location. 3207520Sgblack@eecs.umich.edu data += size; 3214999Sgblack@eecs.umich.edu //Adjust the size to get the remaining bytes. 3227520Sgblack@eecs.umich.edu size = addr + fullSize - secondAddr; 3234999Sgblack@eecs.umich.edu //And access the right address. 3244999Sgblack@eecs.umich.edu addr = secondAddr; 3252623SN/A } 3262623SN/A} 3272623SN/A 3287520Sgblack@eecs.umich.edu 3292623SN/AFault 3308444Sgblack@eecs.umich.eduAtomicSimpleCPU::writeMem(uint8_t *data, unsigned size, 3318444Sgblack@eecs.umich.edu Addr addr, unsigned flags, uint64_t *res) 3322623SN/A{ 3333169Sstever@eecs.umich.edu // use the CPU's statically allocated write request and packet objects 3344870Sstever@eecs.umich.edu Request *req = &data_write_req; 3352623SN/A 3362623SN/A if (traceData) { 3372623SN/A traceData->setAddr(addr); 3382623SN/A } 3392623SN/A 3404999Sgblack@eecs.umich.edu //The block size of our peer. 3416227Snate@binkert.org unsigned blockSize = dcachePort.peerBlockSize(); 3424999Sgblack@eecs.umich.edu //The size of the data we're trying to read. 3437520Sgblack@eecs.umich.edu int fullSize = size; 3442623SN/A 3454999Sgblack@eecs.umich.edu //The address of the second part of this access if it needs to be split 3464999Sgblack@eecs.umich.edu //across a cache line boundary. 3477520Sgblack@eecs.umich.edu Addr secondAddr = roundDown(addr + size - 1, blockSize); 3484999Sgblack@eecs.umich.edu 3494999Sgblack@eecs.umich.edu if(secondAddr > addr) 3507520Sgblack@eecs.umich.edu size = secondAddr - addr; 3514999Sgblack@eecs.umich.edu 3524999Sgblack@eecs.umich.edu dcache_latency = 0; 3534999Sgblack@eecs.umich.edu 3544999Sgblack@eecs.umich.edu while(1) { 3558832SAli.Saidi@ARM.com req->setVirt(0, addr, size, flags, dataMasterId(), thread->pcState().instAddr()); 3564999Sgblack@eecs.umich.edu 3574999Sgblack@eecs.umich.edu // translate to physical address 3586023Snate@binkert.org Fault fault = thread->dtb->translateAtomic(req, tc, BaseTLB::Write); 3594999Sgblack@eecs.umich.edu 3604999Sgblack@eecs.umich.edu // Now do the access. 3614999Sgblack@eecs.umich.edu if (fault == NoFault) { 3624999Sgblack@eecs.umich.edu MemCmd cmd = MemCmd::WriteReq; // default 3634999Sgblack@eecs.umich.edu bool do_access = true; // flag to suppress cache access 3644999Sgblack@eecs.umich.edu 3656102Sgblack@eecs.umich.edu if (req->isLLSC()) { 3664999Sgblack@eecs.umich.edu cmd = MemCmd::StoreCondReq; 3674999Sgblack@eecs.umich.edu do_access = TheISA::handleLockedWrite(thread, req); 3684999Sgblack@eecs.umich.edu } else if (req->isSwap()) { 3694999Sgblack@eecs.umich.edu cmd = MemCmd::SwapReq; 3704999Sgblack@eecs.umich.edu if (req->isCondSwap()) { 3714999Sgblack@eecs.umich.edu assert(res); 3724999Sgblack@eecs.umich.edu req->setExtraData(*res); 3734999Sgblack@eecs.umich.edu } 3744999Sgblack@eecs.umich.edu } 3754999Sgblack@eecs.umich.edu 3766623Sgblack@eecs.umich.edu if (do_access && !req->getFlags().isSet(Request::NO_ACCESS)) { 3774999Sgblack@eecs.umich.edu Packet pkt = Packet(req, cmd, Packet::Broadcast); 3787520Sgblack@eecs.umich.edu pkt.dataStatic(data); 3794999Sgblack@eecs.umich.edu 3808105Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 3814999Sgblack@eecs.umich.edu dcache_latency += 3824999Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread->getTC(), &pkt); 3834999Sgblack@eecs.umich.edu } else { 3848931Sandreas.hansson@arm.com if (fastmem && system->isMemAddr(pkt.getAddr())) 3858931Sandreas.hansson@arm.com system->getPhysMem().access(&pkt); 3864999Sgblack@eecs.umich.edu else 3874999Sgblack@eecs.umich.edu dcache_latency += dcachePort.sendAtomic(&pkt); 3884999Sgblack@eecs.umich.edu } 3894999Sgblack@eecs.umich.edu dcache_access = true; 3904999Sgblack@eecs.umich.edu assert(!pkt.isError()); 3914999Sgblack@eecs.umich.edu 3924999Sgblack@eecs.umich.edu if (req->isSwap()) { 3934999Sgblack@eecs.umich.edu assert(res); 3947520Sgblack@eecs.umich.edu memcpy(res, pkt.getPtr<uint8_t>(), fullSize); 3954999Sgblack@eecs.umich.edu } 3964999Sgblack@eecs.umich.edu } 3974999Sgblack@eecs.umich.edu 3984999Sgblack@eecs.umich.edu if (res && !req->isSwap()) { 3994999Sgblack@eecs.umich.edu *res = req->getExtraData(); 4004878Sstever@eecs.umich.edu } 4014040Ssaidi@eecs.umich.edu } 4024040Ssaidi@eecs.umich.edu 4034999Sgblack@eecs.umich.edu //If there's a fault or we don't need to access a second cache line, 4044999Sgblack@eecs.umich.edu //stop now. 4054999Sgblack@eecs.umich.edu if (fault != NoFault || secondAddr <= addr) 4064999Sgblack@eecs.umich.edu { 4076078Sgblack@eecs.umich.edu if (req->isLocked() && fault == NoFault) { 4086078Sgblack@eecs.umich.edu assert(locked); 4096078Sgblack@eecs.umich.edu locked = false; 4106078Sgblack@eecs.umich.edu } 4116739Sgblack@eecs.umich.edu if (fault != NoFault && req->isPrefetch()) { 4126739Sgblack@eecs.umich.edu return NoFault; 4136739Sgblack@eecs.umich.edu } else { 4146739Sgblack@eecs.umich.edu return fault; 4156739Sgblack@eecs.umich.edu } 4163170Sstever@eecs.umich.edu } 4173170Sstever@eecs.umich.edu 4184999Sgblack@eecs.umich.edu /* 4194999Sgblack@eecs.umich.edu * Set up for accessing the second cache line. 4204999Sgblack@eecs.umich.edu */ 4214999Sgblack@eecs.umich.edu 4224999Sgblack@eecs.umich.edu //Move the pointer we're reading into to the correct location. 4237520Sgblack@eecs.umich.edu data += size; 4244999Sgblack@eecs.umich.edu //Adjust the size to get the remaining bytes. 4257520Sgblack@eecs.umich.edu size = addr + fullSize - secondAddr; 4264999Sgblack@eecs.umich.edu //And access the right address. 4274999Sgblack@eecs.umich.edu addr = secondAddr; 4282623SN/A } 4292623SN/A} 4302623SN/A 4312623SN/A 4322623SN/Avoid 4332623SN/AAtomicSimpleCPU::tick() 4342623SN/A{ 4354940Snate@binkert.org DPRINTF(SimpleCPU, "Tick\n"); 4364940Snate@binkert.org 4375487Snate@binkert.org Tick latency = 0; 4382623SN/A 4396078Sgblack@eecs.umich.edu for (int i = 0; i < width || locked; ++i) { 4402623SN/A numCycles++; 4412623SN/A 4423387Sgblack@eecs.umich.edu if (!curStaticInst || !curStaticInst->isDelayedCommit()) 4433387Sgblack@eecs.umich.edu checkForInterrupts(); 4442626SN/A 4455348Ssaidi@eecs.umich.edu checkPcEventQueue(); 4468143SAli.Saidi@ARM.com // We must have just got suspended by a PC event 4478143SAli.Saidi@ARM.com if (_status == Idle) 4488143SAli.Saidi@ARM.com return; 4495348Ssaidi@eecs.umich.edu 4505669Sgblack@eecs.umich.edu Fault fault = NoFault; 4515669Sgblack@eecs.umich.edu 4527720Sgblack@eecs.umich.edu TheISA::PCState pcState = thread->pcState(); 4537720Sgblack@eecs.umich.edu 4547720Sgblack@eecs.umich.edu bool needToFetch = !isRomMicroPC(pcState.microPC()) && 4557720Sgblack@eecs.umich.edu !curMacroStaticInst; 4567720Sgblack@eecs.umich.edu if (needToFetch) { 4575894Sgblack@eecs.umich.edu setupFetchRequest(&ifetch_req); 4586023Snate@binkert.org fault = thread->itb->translateAtomic(&ifetch_req, tc, 4596023Snate@binkert.org BaseTLB::Execute); 4605894Sgblack@eecs.umich.edu } 4612623SN/A 4622623SN/A if (fault == NoFault) { 4634182Sgblack@eecs.umich.edu Tick icache_latency = 0; 4644182Sgblack@eecs.umich.edu bool icache_access = false; 4654182Sgblack@eecs.umich.edu dcache_access = false; // assume no dcache access 4662662Sstever@eecs.umich.edu 4677720Sgblack@eecs.umich.edu if (needToFetch) { 4685694Sgblack@eecs.umich.edu // This is commented out because the predecoder would act like 4695694Sgblack@eecs.umich.edu // a tiny cache otherwise. It wouldn't be flushed when needed 4705694Sgblack@eecs.umich.edu // like the I cache. It should be flushed, and when that works 4715694Sgblack@eecs.umich.edu // this code should be uncommented. 4725669Sgblack@eecs.umich.edu //Fetch more instruction memory if necessary 4735669Sgblack@eecs.umich.edu //if(predecoder.needMoreBytes()) 4745669Sgblack@eecs.umich.edu //{ 4755669Sgblack@eecs.umich.edu icache_access = true; 4765669Sgblack@eecs.umich.edu Packet ifetch_pkt = Packet(&ifetch_req, MemCmd::ReadReq, 4775669Sgblack@eecs.umich.edu Packet::Broadcast); 4785669Sgblack@eecs.umich.edu ifetch_pkt.dataStatic(&inst); 4792623SN/A 4808931Sandreas.hansson@arm.com if (fastmem && system->isMemAddr(ifetch_pkt.getAddr())) 4818931Sandreas.hansson@arm.com system->getPhysMem().access(&ifetch_pkt); 4825669Sgblack@eecs.umich.edu else 4835669Sgblack@eecs.umich.edu icache_latency = icachePort.sendAtomic(&ifetch_pkt); 4844968Sacolyte@umich.edu 4855669Sgblack@eecs.umich.edu assert(!ifetch_pkt.isError()); 4864968Sacolyte@umich.edu 4875669Sgblack@eecs.umich.edu // ifetch_req is initialized to read the instruction directly 4885669Sgblack@eecs.umich.edu // into the CPU object's inst field. 4895669Sgblack@eecs.umich.edu //} 4905669Sgblack@eecs.umich.edu } 4914182Sgblack@eecs.umich.edu 4922623SN/A preExecute(); 4933814Ssaidi@eecs.umich.edu 4945001Sgblack@eecs.umich.edu if (curStaticInst) { 4954182Sgblack@eecs.umich.edu fault = curStaticInst->execute(this, traceData); 4964998Sgblack@eecs.umich.edu 4974998Sgblack@eecs.umich.edu // keep an instruction count 4984998Sgblack@eecs.umich.edu if (fault == NoFault) 4994998Sgblack@eecs.umich.edu countInst(); 5007655Sali.saidi@arm.com else if (traceData && !DTRACE(ExecFaulting)) { 5015001Sgblack@eecs.umich.edu delete traceData; 5025001Sgblack@eecs.umich.edu traceData = NULL; 5035001Sgblack@eecs.umich.edu } 5044998Sgblack@eecs.umich.edu 5054182Sgblack@eecs.umich.edu postExecute(); 5064182Sgblack@eecs.umich.edu } 5072623SN/A 5083814Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 5094539Sgblack@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 5104539Sgblack@eecs.umich.edu curStaticInst->isFirstMicroop())) 5113814Ssaidi@eecs.umich.edu instCnt++; 5123814Ssaidi@eecs.umich.edu 5135487Snate@binkert.org Tick stall_ticks = 0; 5145487Snate@binkert.org if (simulate_inst_stalls && icache_access) 5155487Snate@binkert.org stall_ticks += icache_latency; 5165487Snate@binkert.org 5175487Snate@binkert.org if (simulate_data_stalls && dcache_access) 5185487Snate@binkert.org stall_ticks += dcache_latency; 5195487Snate@binkert.org 5205487Snate@binkert.org if (stall_ticks) { 5215487Snate@binkert.org Tick stall_cycles = stall_ticks / ticks(1); 5225487Snate@binkert.org Tick aligned_stall_ticks = ticks(stall_cycles); 5235487Snate@binkert.org 5245487Snate@binkert.org if (aligned_stall_ticks < stall_ticks) 5255487Snate@binkert.org aligned_stall_ticks += 1; 5265487Snate@binkert.org 5275487Snate@binkert.org latency += aligned_stall_ticks; 5282623SN/A } 5292623SN/A 5302623SN/A } 5314377Sgblack@eecs.umich.edu if(fault != NoFault || !stayAtPC) 5324182Sgblack@eecs.umich.edu advancePC(fault); 5332623SN/A } 5342623SN/A 5355487Snate@binkert.org // instruction takes at least one cycle 5365487Snate@binkert.org if (latency < ticks(1)) 5375487Snate@binkert.org latency = ticks(1); 5385487Snate@binkert.org 5392626SN/A if (_status != Idle) 5407823Ssteve.reinhardt@amd.com schedule(tickEvent, curTick() + latency); 5412623SN/A} 5422623SN/A 5432623SN/A 5445315Sstever@gmail.comvoid 5455315Sstever@gmail.comAtomicSimpleCPU::printAddr(Addr a) 5465315Sstever@gmail.com{ 5475315Sstever@gmail.com dcachePort.printAddr(a); 5485315Sstever@gmail.com} 5495315Sstever@gmail.com 5505315Sstever@gmail.com 5512623SN/A//////////////////////////////////////////////////////////////////////// 5522623SN/A// 5532623SN/A// AtomicSimpleCPU Simulation Object 5542623SN/A// 5554762Snate@binkert.orgAtomicSimpleCPU * 5564762Snate@binkert.orgAtomicSimpleCPUParams::create() 5572623SN/A{ 5585529Snate@binkert.org numThreads = 1; 5598779Sgblack@eecs.umich.edu if (!FullSystem && workload.size() != 1) 5604762Snate@binkert.org panic("only one workload allowed"); 5615529Snate@binkert.org return new AtomicSimpleCPU(this); 5622623SN/A} 563