atomic.cc revision 8711
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"
328105Sgblack@eecs.umich.edu#include "arch/mmapped_ipr.hh"
332623SN/A#include "arch/utility.hh"
344040Ssaidi@eecs.umich.edu#include "base/bigint.hh"
356658Snate@binkert.org#include "config/the_isa.hh"
368229Snate@binkert.org#include "cpu/simple/atomic.hh"
372623SN/A#include "cpu/exetrace.hh"
388232Snate@binkert.org#include "debug/ExecFaulting.hh"
398232Snate@binkert.org#include "debug/SimpleCPU.hh"
403348Sbinkertn@umich.edu#include "mem/packet.hh"
413348Sbinkertn@umich.edu#include "mem/packet_access.hh"
424762Snate@binkert.org#include "params/AtomicSimpleCPU.hh"
437678Sgblack@eecs.umich.edu#include "sim/faults.hh"
442901Ssaidi@eecs.umich.edu#include "sim/system.hh"
452623SN/A
462623SN/Ausing namespace std;
472623SN/Ausing namespace TheISA;
482623SN/A
492623SN/AAtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c)
505606Snate@binkert.org    : Event(CPU_Tick_Pri), cpu(c)
512623SN/A{
522623SN/A}
532623SN/A
542623SN/A
552623SN/Avoid
562623SN/AAtomicSimpleCPU::TickEvent::process()
572623SN/A{
582623SN/A    cpu->tick();
592623SN/A}
602623SN/A
612623SN/Aconst char *
625336Shines@cs.fsu.eduAtomicSimpleCPU::TickEvent::description() const
632623SN/A{
644873Sstever@eecs.umich.edu    return "AtomicSimpleCPU tick";
652623SN/A}
662623SN/A
672856Srdreslin@umich.eduPort *
686227Snate@binkert.orgAtomicSimpleCPU::getPort(const string &if_name, int idx)
692856Srdreslin@umich.edu{
702856Srdreslin@umich.edu    if (if_name == "dcache_port")
712856Srdreslin@umich.edu        return &dcachePort;
722856Srdreslin@umich.edu    else if (if_name == "icache_port")
732856Srdreslin@umich.edu        return &icachePort;
744968Sacolyte@umich.edu    else if (if_name == "physmem_port") {
754968Sacolyte@umich.edu        hasPhysMemPort = true;
764968Sacolyte@umich.edu        return &physmemPort;
774968Sacolyte@umich.edu    }
782856Srdreslin@umich.edu    else
792856Srdreslin@umich.edu        panic("No Such Port\n");
802856Srdreslin@umich.edu}
812623SN/A
822623SN/Avoid
832623SN/AAtomicSimpleCPU::init()
842623SN/A{
852623SN/A    BaseCPU::init();
862623SN/A#if FULL_SYSTEM
876221Snate@binkert.org    ThreadID size = threadContexts.size();
886221Snate@binkert.org    for (ThreadID i = 0; i < size; ++i) {
892680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
902623SN/A
912623SN/A        // initialize CPU, including PC
925714Shsul@eecs.umich.edu        TheISA::initCPU(tc, tc->contextId());
932623SN/A    }
948706Sandreas.hansson@arm.com
958706Sandreas.hansson@arm.com    // Initialise the ThreadContext's memory proxies
968706Sandreas.hansson@arm.com    tcBase()->initMemProxies(tcBase());
972623SN/A#endif
984968Sacolyte@umich.edu    if (hasPhysMemPort) {
998711Sandreas.hansson@arm.com        AddrRangeList pmAddrList = physmemPort.getPeer()->getAddrRanges();
1004968Sacolyte@umich.edu        physMemAddr = *pmAddrList.begin();
1014968Sacolyte@umich.edu    }
1025714Shsul@eecs.umich.edu    // Atomic doesn't do MT right now, so contextId == threadId
1035712Shsul@eecs.umich.edu    ifetch_req.setThreadContext(_cpuId, 0); // Add thread ID if we add MT
1045712Shsul@eecs.umich.edu    data_read_req.setThreadContext(_cpuId, 0); // Add thread ID here too
1055712Shsul@eecs.umich.edu    data_write_req.setThreadContext(_cpuId, 0); // Add thread ID here too
1062623SN/A}
1072623SN/A
1085529Snate@binkert.orgAtomicSimpleCPU::AtomicSimpleCPU(AtomicSimpleCPUParams *p)
1096078Sgblack@eecs.umich.edu    : BaseSimpleCPU(p), tickEvent(this), width(p->width), locked(false),
1105487Snate@binkert.org      simulate_data_stalls(p->simulate_data_stalls),
1115487Snate@binkert.org      simulate_inst_stalls(p->simulate_inst_stalls),
1124968Sacolyte@umich.edu      icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this),
1134968Sacolyte@umich.edu      physmemPort(name() + "-iport", this), hasPhysMemPort(false)
1142623SN/A{
1152623SN/A    _status = Idle;
1162623SN/A}
1172623SN/A
1182623SN/A
1192623SN/AAtomicSimpleCPU::~AtomicSimpleCPU()
1202623SN/A{
1216775SBrad.Beckmann@amd.com    if (tickEvent.scheduled()) {
1226775SBrad.Beckmann@amd.com        deschedule(tickEvent);
1236775SBrad.Beckmann@amd.com    }
1242623SN/A}
1252623SN/A
1262623SN/Avoid
1272623SN/AAtomicSimpleCPU::serialize(ostream &os)
1282623SN/A{
1292915Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
1302915Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
1316078Sgblack@eecs.umich.edu    SERIALIZE_SCALAR(locked);
1323145Shsul@eecs.umich.edu    BaseSimpleCPU::serialize(os);
1332623SN/A    nameOut(os, csprintf("%s.tickEvent", name()));
1342623SN/A    tickEvent.serialize(os);
1352623SN/A}
1362623SN/A
1372623SN/Avoid
1382623SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1392623SN/A{
1402915Sktlim@umich.edu    SimObject::State so_state;
1412915Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
1426078Sgblack@eecs.umich.edu    UNSERIALIZE_SCALAR(locked);
1433145Shsul@eecs.umich.edu    BaseSimpleCPU::unserialize(cp, section);
1442915Sktlim@umich.edu    tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
1452915Sktlim@umich.edu}
1462915Sktlim@umich.edu
1472915Sktlim@umich.eduvoid
1482915Sktlim@umich.eduAtomicSimpleCPU::resume()
1492915Sktlim@umich.edu{
1505220Ssaidi@eecs.umich.edu    if (_status == Idle || _status == SwitchedOut)
1515220Ssaidi@eecs.umich.edu        return;
1525220Ssaidi@eecs.umich.edu
1534940Snate@binkert.org    DPRINTF(SimpleCPU, "Resume\n");
1545220Ssaidi@eecs.umich.edu    assert(system->getMemoryMode() == Enums::atomic);
1553324Shsul@eecs.umich.edu
1565220Ssaidi@eecs.umich.edu    changeState(SimObject::Running);
1575220Ssaidi@eecs.umich.edu    if (thread->status() == ThreadContext::Active) {
1585606Snate@binkert.org        if (!tickEvent.scheduled())
1595606Snate@binkert.org            schedule(tickEvent, nextCycle());
1602915Sktlim@umich.edu    }
1617897Shestness@cs.utexas.edu    system->totalNumInsts = 0;
1622623SN/A}
1632623SN/A
1642623SN/Avoid
1652798Sktlim@umich.eduAtomicSimpleCPU::switchOut()
1662623SN/A{
1675496Ssaidi@eecs.umich.edu    assert(_status == Running || _status == Idle);
1682798Sktlim@umich.edu    _status = SwitchedOut;
1692623SN/A
1702798Sktlim@umich.edu    tickEvent.squash();
1712623SN/A}
1722623SN/A
1732623SN/A
1742623SN/Avoid
1752623SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
1762623SN/A{
1774192Sktlim@umich.edu    BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort);
1782623SN/A
1792623SN/A    assert(!tickEvent.scheduled());
1802623SN/A
1812680Sktlim@umich.edu    // if any of this CPU's ThreadContexts are active, mark the CPU as
1822623SN/A    // running and schedule its tick event.
1836221Snate@binkert.org    ThreadID size = threadContexts.size();
1846221Snate@binkert.org    for (ThreadID i = 0; i < size; ++i) {
1852680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
1862680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
1872623SN/A            _status = Running;
1885606Snate@binkert.org            schedule(tickEvent, nextCycle());
1892623SN/A            break;
1902623SN/A        }
1912623SN/A    }
1923512Sktlim@umich.edu    if (_status != Running) {
1933512Sktlim@umich.edu        _status = Idle;
1943512Sktlim@umich.edu    }
1955169Ssaidi@eecs.umich.edu    assert(threadContexts.size() == 1);
1965712Shsul@eecs.umich.edu    ifetch_req.setThreadContext(_cpuId, 0); // Add thread ID if we add MT
1975712Shsul@eecs.umich.edu    data_read_req.setThreadContext(_cpuId, 0); // Add thread ID here too
1985712Shsul@eecs.umich.edu    data_write_req.setThreadContext(_cpuId, 0); // Add thread ID here too
1992623SN/A}
2002623SN/A
2012623SN/A
2022623SN/Avoid
2032623SN/AAtomicSimpleCPU::activateContext(int thread_num, int delay)
2042623SN/A{
2054940Snate@binkert.org    DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay);
2064940Snate@binkert.org
2072623SN/A    assert(thread_num == 0);
2082683Sktlim@umich.edu    assert(thread);
2092623SN/A
2102623SN/A    assert(_status == Idle);
2112623SN/A    assert(!tickEvent.scheduled());
2122623SN/A
2132623SN/A    notIdleFraction++;
2145101Ssaidi@eecs.umich.edu    numCycles += tickToCycles(thread->lastActivate - thread->lastSuspend);
2153686Sktlim@umich.edu
2163430Sgblack@eecs.umich.edu    //Make sure ticks are still on multiples of cycles
2177823Ssteve.reinhardt@amd.com    schedule(tickEvent, nextCycle(curTick() + ticks(delay)));
2182623SN/A    _status = Running;
2192623SN/A}
2202623SN/A
2212623SN/A
2222623SN/Avoid
2232623SN/AAtomicSimpleCPU::suspendContext(int thread_num)
2242623SN/A{
2254940Snate@binkert.org    DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num);
2264940Snate@binkert.org
2272623SN/A    assert(thread_num == 0);
2282683Sktlim@umich.edu    assert(thread);
2292623SN/A
2306043Sgblack@eecs.umich.edu    if (_status == Idle)
2316043Sgblack@eecs.umich.edu        return;
2326043Sgblack@eecs.umich.edu
2332623SN/A    assert(_status == Running);
2342626SN/A
2352626SN/A    // tick event may not be scheduled if this gets called from inside
2362626SN/A    // an instruction's execution, e.g. "quiesce"
2372626SN/A    if (tickEvent.scheduled())
2385606Snate@binkert.org        deschedule(tickEvent);
2392623SN/A
2402623SN/A    notIdleFraction--;
2412623SN/A    _status = Idle;
2422623SN/A}
2432623SN/A
2442623SN/A
2452623SN/AFault
2468444Sgblack@eecs.umich.eduAtomicSimpleCPU::readMem(Addr addr, uint8_t * data,
2478444Sgblack@eecs.umich.edu                         unsigned size, unsigned flags)
2482623SN/A{
2493169Sstever@eecs.umich.edu    // use the CPU's statically allocated read request and packet objects
2504870Sstever@eecs.umich.edu    Request *req = &data_read_req;
2512623SN/A
2522623SN/A    if (traceData) {
2532623SN/A        traceData->setAddr(addr);
2542623SN/A    }
2552623SN/A
2564999Sgblack@eecs.umich.edu    //The block size of our peer.
2576227Snate@binkert.org    unsigned blockSize = dcachePort.peerBlockSize();
2584999Sgblack@eecs.umich.edu    //The size of the data we're trying to read.
2597520Sgblack@eecs.umich.edu    int fullSize = size;
2602623SN/A
2614999Sgblack@eecs.umich.edu    //The address of the second part of this access if it needs to be split
2624999Sgblack@eecs.umich.edu    //across a cache line boundary.
2637520Sgblack@eecs.umich.edu    Addr secondAddr = roundDown(addr + size - 1, blockSize);
2644999Sgblack@eecs.umich.edu
2657520Sgblack@eecs.umich.edu    if (secondAddr > addr)
2667520Sgblack@eecs.umich.edu        size = secondAddr - addr;
2674999Sgblack@eecs.umich.edu
2684999Sgblack@eecs.umich.edu    dcache_latency = 0;
2694999Sgblack@eecs.umich.edu
2707520Sgblack@eecs.umich.edu    while (1) {
2717720Sgblack@eecs.umich.edu        req->setVirt(0, addr, size, flags, thread->pcState().instAddr());
2724999Sgblack@eecs.umich.edu
2734999Sgblack@eecs.umich.edu        // translate to physical address
2746023Snate@binkert.org        Fault fault = thread->dtb->translateAtomic(req, tc, BaseTLB::Read);
2754999Sgblack@eecs.umich.edu
2764999Sgblack@eecs.umich.edu        // Now do the access.
2776623Sgblack@eecs.umich.edu        if (fault == NoFault && !req->getFlags().isSet(Request::NO_ACCESS)) {
2784999Sgblack@eecs.umich.edu            Packet pkt = Packet(req,
2796102Sgblack@eecs.umich.edu                    req->isLLSC() ? MemCmd::LoadLockedReq : MemCmd::ReadReq,
2804999Sgblack@eecs.umich.edu                    Packet::Broadcast);
2817520Sgblack@eecs.umich.edu            pkt.dataStatic(data);
2824999Sgblack@eecs.umich.edu
2838105Sgblack@eecs.umich.edu            if (req->isMmappedIpr())
2844999Sgblack@eecs.umich.edu                dcache_latency += TheISA::handleIprRead(thread->getTC(), &pkt);
2854999Sgblack@eecs.umich.edu            else {
2864999Sgblack@eecs.umich.edu                if (hasPhysMemPort && pkt.getAddr() == physMemAddr)
2874999Sgblack@eecs.umich.edu                    dcache_latency += physmemPort.sendAtomic(&pkt);
2884999Sgblack@eecs.umich.edu                else
2894999Sgblack@eecs.umich.edu                    dcache_latency += dcachePort.sendAtomic(&pkt);
2904999Sgblack@eecs.umich.edu            }
2914999Sgblack@eecs.umich.edu            dcache_access = true;
2925012Sgblack@eecs.umich.edu
2934999Sgblack@eecs.umich.edu            assert(!pkt.isError());
2944999Sgblack@eecs.umich.edu
2956102Sgblack@eecs.umich.edu            if (req->isLLSC()) {
2964999Sgblack@eecs.umich.edu                TheISA::handleLockedRead(thread, req);
2974999Sgblack@eecs.umich.edu            }
2984968Sacolyte@umich.edu        }
2994986Ssaidi@eecs.umich.edu
3004999Sgblack@eecs.umich.edu        //If there's a fault, return it
3016739Sgblack@eecs.umich.edu        if (fault != NoFault) {
3026739Sgblack@eecs.umich.edu            if (req->isPrefetch()) {
3036739Sgblack@eecs.umich.edu                return NoFault;
3046739Sgblack@eecs.umich.edu            } else {
3056739Sgblack@eecs.umich.edu                return fault;
3066739Sgblack@eecs.umich.edu            }
3076739Sgblack@eecs.umich.edu        }
3086739Sgblack@eecs.umich.edu
3094999Sgblack@eecs.umich.edu        //If we don't need to access a second cache line, stop now.
3104999Sgblack@eecs.umich.edu        if (secondAddr <= addr)
3114999Sgblack@eecs.umich.edu        {
3126078Sgblack@eecs.umich.edu            if (req->isLocked() && fault == NoFault) {
3136078Sgblack@eecs.umich.edu                assert(!locked);
3146078Sgblack@eecs.umich.edu                locked = true;
3156078Sgblack@eecs.umich.edu            }
3164999Sgblack@eecs.umich.edu            return fault;
3174968Sacolyte@umich.edu        }
3183170Sstever@eecs.umich.edu
3194999Sgblack@eecs.umich.edu        /*
3204999Sgblack@eecs.umich.edu         * Set up for accessing the second cache line.
3214999Sgblack@eecs.umich.edu         */
3224999Sgblack@eecs.umich.edu
3234999Sgblack@eecs.umich.edu        //Move the pointer we're reading into to the correct location.
3247520Sgblack@eecs.umich.edu        data += size;
3254999Sgblack@eecs.umich.edu        //Adjust the size to get the remaining bytes.
3267520Sgblack@eecs.umich.edu        size = addr + fullSize - secondAddr;
3274999Sgblack@eecs.umich.edu        //And access the right address.
3284999Sgblack@eecs.umich.edu        addr = secondAddr;
3292623SN/A    }
3302623SN/A}
3312623SN/A
3327520Sgblack@eecs.umich.edu
3332623SN/AFault
3348444Sgblack@eecs.umich.eduAtomicSimpleCPU::writeMem(uint8_t *data, unsigned size,
3358444Sgblack@eecs.umich.edu                          Addr addr, unsigned flags, uint64_t *res)
3362623SN/A{
3373169Sstever@eecs.umich.edu    // use the CPU's statically allocated write request and packet objects
3384870Sstever@eecs.umich.edu    Request *req = &data_write_req;
3392623SN/A
3402623SN/A    if (traceData) {
3412623SN/A        traceData->setAddr(addr);
3422623SN/A    }
3432623SN/A
3444999Sgblack@eecs.umich.edu    //The block size of our peer.
3456227Snate@binkert.org    unsigned blockSize = dcachePort.peerBlockSize();
3464999Sgblack@eecs.umich.edu    //The size of the data we're trying to read.
3477520Sgblack@eecs.umich.edu    int fullSize = size;
3482623SN/A
3494999Sgblack@eecs.umich.edu    //The address of the second part of this access if it needs to be split
3504999Sgblack@eecs.umich.edu    //across a cache line boundary.
3517520Sgblack@eecs.umich.edu    Addr secondAddr = roundDown(addr + size - 1, blockSize);
3524999Sgblack@eecs.umich.edu
3534999Sgblack@eecs.umich.edu    if(secondAddr > addr)
3547520Sgblack@eecs.umich.edu        size = secondAddr - addr;
3554999Sgblack@eecs.umich.edu
3564999Sgblack@eecs.umich.edu    dcache_latency = 0;
3574999Sgblack@eecs.umich.edu
3584999Sgblack@eecs.umich.edu    while(1) {
3597720Sgblack@eecs.umich.edu        req->setVirt(0, addr, size, flags, thread->pcState().instAddr());
3604999Sgblack@eecs.umich.edu
3614999Sgblack@eecs.umich.edu        // translate to physical address
3626023Snate@binkert.org        Fault fault = thread->dtb->translateAtomic(req, tc, BaseTLB::Write);
3634999Sgblack@eecs.umich.edu
3644999Sgblack@eecs.umich.edu        // Now do the access.
3654999Sgblack@eecs.umich.edu        if (fault == NoFault) {
3664999Sgblack@eecs.umich.edu            MemCmd cmd = MemCmd::WriteReq; // default
3674999Sgblack@eecs.umich.edu            bool do_access = true;  // flag to suppress cache access
3684999Sgblack@eecs.umich.edu
3696102Sgblack@eecs.umich.edu            if (req->isLLSC()) {
3704999Sgblack@eecs.umich.edu                cmd = MemCmd::StoreCondReq;
3714999Sgblack@eecs.umich.edu                do_access = TheISA::handleLockedWrite(thread, req);
3724999Sgblack@eecs.umich.edu            } else if (req->isSwap()) {
3734999Sgblack@eecs.umich.edu                cmd = MemCmd::SwapReq;
3744999Sgblack@eecs.umich.edu                if (req->isCondSwap()) {
3754999Sgblack@eecs.umich.edu                    assert(res);
3764999Sgblack@eecs.umich.edu                    req->setExtraData(*res);
3774999Sgblack@eecs.umich.edu                }
3784999Sgblack@eecs.umich.edu            }
3794999Sgblack@eecs.umich.edu
3806623Sgblack@eecs.umich.edu            if (do_access && !req->getFlags().isSet(Request::NO_ACCESS)) {
3814999Sgblack@eecs.umich.edu                Packet pkt = Packet(req, cmd, Packet::Broadcast);
3827520Sgblack@eecs.umich.edu                pkt.dataStatic(data);
3834999Sgblack@eecs.umich.edu
3848105Sgblack@eecs.umich.edu                if (req->isMmappedIpr()) {
3854999Sgblack@eecs.umich.edu                    dcache_latency +=
3864999Sgblack@eecs.umich.edu                        TheISA::handleIprWrite(thread->getTC(), &pkt);
3874999Sgblack@eecs.umich.edu                } else {
3884999Sgblack@eecs.umich.edu                    if (hasPhysMemPort && pkt.getAddr() == physMemAddr)
3894999Sgblack@eecs.umich.edu                        dcache_latency += physmemPort.sendAtomic(&pkt);
3904999Sgblack@eecs.umich.edu                    else
3914999Sgblack@eecs.umich.edu                        dcache_latency += dcachePort.sendAtomic(&pkt);
3924999Sgblack@eecs.umich.edu                }
3934999Sgblack@eecs.umich.edu                dcache_access = true;
3944999Sgblack@eecs.umich.edu                assert(!pkt.isError());
3954999Sgblack@eecs.umich.edu
3964999Sgblack@eecs.umich.edu                if (req->isSwap()) {
3974999Sgblack@eecs.umich.edu                    assert(res);
3987520Sgblack@eecs.umich.edu                    memcpy(res, pkt.getPtr<uint8_t>(), fullSize);
3994999Sgblack@eecs.umich.edu                }
4004999Sgblack@eecs.umich.edu            }
4014999Sgblack@eecs.umich.edu
4024999Sgblack@eecs.umich.edu            if (res && !req->isSwap()) {
4034999Sgblack@eecs.umich.edu                *res = req->getExtraData();
4044878Sstever@eecs.umich.edu            }
4054040Ssaidi@eecs.umich.edu        }
4064040Ssaidi@eecs.umich.edu
4074999Sgblack@eecs.umich.edu        //If there's a fault or we don't need to access a second cache line,
4084999Sgblack@eecs.umich.edu        //stop now.
4094999Sgblack@eecs.umich.edu        if (fault != NoFault || secondAddr <= addr)
4104999Sgblack@eecs.umich.edu        {
4116078Sgblack@eecs.umich.edu            if (req->isLocked() && fault == NoFault) {
4126078Sgblack@eecs.umich.edu                assert(locked);
4136078Sgblack@eecs.umich.edu                locked = false;
4146078Sgblack@eecs.umich.edu            }
4156739Sgblack@eecs.umich.edu            if (fault != NoFault && req->isPrefetch()) {
4166739Sgblack@eecs.umich.edu                return NoFault;
4176739Sgblack@eecs.umich.edu            } else {
4186739Sgblack@eecs.umich.edu                return fault;
4196739Sgblack@eecs.umich.edu            }
4203170Sstever@eecs.umich.edu        }
4213170Sstever@eecs.umich.edu
4224999Sgblack@eecs.umich.edu        /*
4234999Sgblack@eecs.umich.edu         * Set up for accessing the second cache line.
4244999Sgblack@eecs.umich.edu         */
4254999Sgblack@eecs.umich.edu
4264999Sgblack@eecs.umich.edu        //Move the pointer we're reading into to the correct location.
4277520Sgblack@eecs.umich.edu        data += size;
4284999Sgblack@eecs.umich.edu        //Adjust the size to get the remaining bytes.
4297520Sgblack@eecs.umich.edu        size = addr + fullSize - secondAddr;
4304999Sgblack@eecs.umich.edu        //And access the right address.
4314999Sgblack@eecs.umich.edu        addr = secondAddr;
4322623SN/A    }
4332623SN/A}
4342623SN/A
4352623SN/A
4362623SN/Avoid
4372623SN/AAtomicSimpleCPU::tick()
4382623SN/A{
4394940Snate@binkert.org    DPRINTF(SimpleCPU, "Tick\n");
4404940Snate@binkert.org
4415487Snate@binkert.org    Tick latency = 0;
4422623SN/A
4436078Sgblack@eecs.umich.edu    for (int i = 0; i < width || locked; ++i) {
4442623SN/A        numCycles++;
4452623SN/A
4463387Sgblack@eecs.umich.edu        if (!curStaticInst || !curStaticInst->isDelayedCommit())
4473387Sgblack@eecs.umich.edu            checkForInterrupts();
4482626SN/A
4495348Ssaidi@eecs.umich.edu        checkPcEventQueue();
4508143SAli.Saidi@ARM.com        // We must have just got suspended by a PC event
4518143SAli.Saidi@ARM.com        if (_status == Idle)
4528143SAli.Saidi@ARM.com            return;
4535348Ssaidi@eecs.umich.edu
4545669Sgblack@eecs.umich.edu        Fault fault = NoFault;
4555669Sgblack@eecs.umich.edu
4567720Sgblack@eecs.umich.edu        TheISA::PCState pcState = thread->pcState();
4577720Sgblack@eecs.umich.edu
4587720Sgblack@eecs.umich.edu        bool needToFetch = !isRomMicroPC(pcState.microPC()) &&
4597720Sgblack@eecs.umich.edu                           !curMacroStaticInst;
4607720Sgblack@eecs.umich.edu        if (needToFetch) {
4615894Sgblack@eecs.umich.edu            setupFetchRequest(&ifetch_req);
4626023Snate@binkert.org            fault = thread->itb->translateAtomic(&ifetch_req, tc,
4636023Snate@binkert.org                                                 BaseTLB::Execute);
4645894Sgblack@eecs.umich.edu        }
4652623SN/A
4662623SN/A        if (fault == NoFault) {
4674182Sgblack@eecs.umich.edu            Tick icache_latency = 0;
4684182Sgblack@eecs.umich.edu            bool icache_access = false;
4694182Sgblack@eecs.umich.edu            dcache_access = false; // assume no dcache access
4702662Sstever@eecs.umich.edu
4717720Sgblack@eecs.umich.edu            if (needToFetch) {
4725694Sgblack@eecs.umich.edu                // This is commented out because the predecoder would act like
4735694Sgblack@eecs.umich.edu                // a tiny cache otherwise. It wouldn't be flushed when needed
4745694Sgblack@eecs.umich.edu                // like the I cache. It should be flushed, and when that works
4755694Sgblack@eecs.umich.edu                // this code should be uncommented.
4765669Sgblack@eecs.umich.edu                //Fetch more instruction memory if necessary
4775669Sgblack@eecs.umich.edu                //if(predecoder.needMoreBytes())
4785669Sgblack@eecs.umich.edu                //{
4795669Sgblack@eecs.umich.edu                    icache_access = true;
4805669Sgblack@eecs.umich.edu                    Packet ifetch_pkt = Packet(&ifetch_req, MemCmd::ReadReq,
4815669Sgblack@eecs.umich.edu                                               Packet::Broadcast);
4825669Sgblack@eecs.umich.edu                    ifetch_pkt.dataStatic(&inst);
4832623SN/A
4845669Sgblack@eecs.umich.edu                    if (hasPhysMemPort && ifetch_pkt.getAddr() == physMemAddr)
4855669Sgblack@eecs.umich.edu                        icache_latency = physmemPort.sendAtomic(&ifetch_pkt);
4865669Sgblack@eecs.umich.edu                    else
4875669Sgblack@eecs.umich.edu                        icache_latency = icachePort.sendAtomic(&ifetch_pkt);
4884968Sacolyte@umich.edu
4895669Sgblack@eecs.umich.edu                    assert(!ifetch_pkt.isError());
4904968Sacolyte@umich.edu
4915669Sgblack@eecs.umich.edu                    // ifetch_req is initialized to read the instruction directly
4925669Sgblack@eecs.umich.edu                    // into the CPU object's inst field.
4935669Sgblack@eecs.umich.edu                //}
4945669Sgblack@eecs.umich.edu            }
4954182Sgblack@eecs.umich.edu
4962623SN/A            preExecute();
4973814Ssaidi@eecs.umich.edu
4985001Sgblack@eecs.umich.edu            if (curStaticInst) {
4994182Sgblack@eecs.umich.edu                fault = curStaticInst->execute(this, traceData);
5004998Sgblack@eecs.umich.edu
5014998Sgblack@eecs.umich.edu                // keep an instruction count
5024998Sgblack@eecs.umich.edu                if (fault == NoFault)
5034998Sgblack@eecs.umich.edu                    countInst();
5047655Sali.saidi@arm.com                else if (traceData && !DTRACE(ExecFaulting)) {
5055001Sgblack@eecs.umich.edu                    delete traceData;
5065001Sgblack@eecs.umich.edu                    traceData = NULL;
5075001Sgblack@eecs.umich.edu                }
5084998Sgblack@eecs.umich.edu
5094182Sgblack@eecs.umich.edu                postExecute();
5104182Sgblack@eecs.umich.edu            }
5112623SN/A
5123814Ssaidi@eecs.umich.edu            // @todo remove me after debugging with legion done
5134539Sgblack@eecs.umich.edu            if (curStaticInst && (!curStaticInst->isMicroop() ||
5144539Sgblack@eecs.umich.edu                        curStaticInst->isFirstMicroop()))
5153814Ssaidi@eecs.umich.edu                instCnt++;
5163814Ssaidi@eecs.umich.edu
5175487Snate@binkert.org            Tick stall_ticks = 0;
5185487Snate@binkert.org            if (simulate_inst_stalls && icache_access)
5195487Snate@binkert.org                stall_ticks += icache_latency;
5205487Snate@binkert.org
5215487Snate@binkert.org            if (simulate_data_stalls && dcache_access)
5225487Snate@binkert.org                stall_ticks += dcache_latency;
5235487Snate@binkert.org
5245487Snate@binkert.org            if (stall_ticks) {
5255487Snate@binkert.org                Tick stall_cycles = stall_ticks / ticks(1);
5265487Snate@binkert.org                Tick aligned_stall_ticks = ticks(stall_cycles);
5275487Snate@binkert.org
5285487Snate@binkert.org                if (aligned_stall_ticks < stall_ticks)
5295487Snate@binkert.org                    aligned_stall_ticks += 1;
5305487Snate@binkert.org
5315487Snate@binkert.org                latency += aligned_stall_ticks;
5322623SN/A            }
5332623SN/A
5342623SN/A        }
5354377Sgblack@eecs.umich.edu        if(fault != NoFault || !stayAtPC)
5364182Sgblack@eecs.umich.edu            advancePC(fault);
5372623SN/A    }
5382623SN/A
5395487Snate@binkert.org    // instruction takes at least one cycle
5405487Snate@binkert.org    if (latency < ticks(1))
5415487Snate@binkert.org        latency = ticks(1);
5425487Snate@binkert.org
5432626SN/A    if (_status != Idle)
5447823Ssteve.reinhardt@amd.com        schedule(tickEvent, curTick() + latency);
5452623SN/A}
5462623SN/A
5472623SN/A
5485315Sstever@gmail.comvoid
5495315Sstever@gmail.comAtomicSimpleCPU::printAddr(Addr a)
5505315Sstever@gmail.com{
5515315Sstever@gmail.com    dcachePort.printAddr(a);
5525315Sstever@gmail.com}
5535315Sstever@gmail.com
5545315Sstever@gmail.com
5552623SN/A////////////////////////////////////////////////////////////////////////
5562623SN/A//
5572623SN/A//  AtomicSimpleCPU Simulation Object
5582623SN/A//
5594762Snate@binkert.orgAtomicSimpleCPU *
5604762Snate@binkert.orgAtomicSimpleCPUParams::create()
5612623SN/A{
5625529Snate@binkert.org    numThreads = 1;
5635529Snate@binkert.org#if !FULL_SYSTEM
5644762Snate@binkert.org    if (workload.size() != 1)
5654762Snate@binkert.org        panic("only one workload allowed");
5662623SN/A#endif
5675529Snate@binkert.org    return new AtomicSimpleCPU(this);
5682623SN/A}
569