base.cc revision 1977
14120Sgblack@eecs.umich.edu/* 24120Sgblack@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 34120Sgblack@eecs.umich.edu * All rights reserved. 44120Sgblack@eecs.umich.edu * 54120Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 64120Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 74120Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 84120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 94120Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 104120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 114120Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 124120Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 134120Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 144120Sgblack@eecs.umich.edu * this software without specific prior written permission. 154120Sgblack@eecs.umich.edu * 164120Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174120Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184120Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194120Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204120Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214120Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224120Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234120Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244120Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254120Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264120Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274120Sgblack@eecs.umich.edu */ 284120Sgblack@eecs.umich.edu 294120Sgblack@eecs.umich.edu#include <cmath> 304120Sgblack@eecs.umich.edu#include <cstdio> 314120Sgblack@eecs.umich.edu#include <cstdlib> 324120Sgblack@eecs.umich.edu#include <iostream> 334120Sgblack@eecs.umich.edu#include <iomanip> 344120Sgblack@eecs.umich.edu#include <list> 354120Sgblack@eecs.umich.edu#include <sstream> 364120Sgblack@eecs.umich.edu#include <string> 374120Sgblack@eecs.umich.edu 384120Sgblack@eecs.umich.edu#include "base/cprintf.hh" 394120Sgblack@eecs.umich.edu#include "base/inifile.hh" 404120Sgblack@eecs.umich.edu#include "base/loader/symtab.hh" 414120Sgblack@eecs.umich.edu#include "base/misc.hh" 424120Sgblack@eecs.umich.edu#include "base/pollevent.hh" 434120Sgblack@eecs.umich.edu#include "base/range.hh" 444120Sgblack@eecs.umich.edu#include "base/stats/events.hh" 454120Sgblack@eecs.umich.edu#include "base/trace.hh" 464120Sgblack@eecs.umich.edu#include "cpu/base.hh" 474120Sgblack@eecs.umich.edu#include "cpu/exec_context.hh" 484120Sgblack@eecs.umich.edu#include "cpu/exetrace.hh" 494120Sgblack@eecs.umich.edu#include "cpu/profile.hh" 504120Sgblack@eecs.umich.edu#include "cpu/sampler/sampler.hh" 514120Sgblack@eecs.umich.edu#include "cpu/simple/cpu.hh" 524120Sgblack@eecs.umich.edu#include "cpu/smt.hh" 534120Sgblack@eecs.umich.edu#include "cpu/static_inst.hh" 544120Sgblack@eecs.umich.edu#include "kern/kernel_stats.hh" 554120Sgblack@eecs.umich.edu#include "mem/base_mem.hh" 564120Sgblack@eecs.umich.edu#include "mem/mem_interface.hh" 574120Sgblack@eecs.umich.edu#include "sim/builder.hh" 584120Sgblack@eecs.umich.edu#include "sim/debug.hh" 594120Sgblack@eecs.umich.edu#include "sim/host.hh" 604120Sgblack@eecs.umich.edu#include "sim/sim_events.hh" 614139Sgblack@eecs.umich.edu#include "sim/sim_object.hh" 624135Sgblack@eecs.umich.edu#include "sim/stats.hh" 634120Sgblack@eecs.umich.edu 644120Sgblack@eecs.umich.edu#if FULL_SYSTEM 654120Sgblack@eecs.umich.edu#include "base/remote_gdb.hh" 665114Sgblack@eecs.umich.edu#include "mem/functional/memory_control.hh" 675114Sgblack@eecs.umich.edu#include "mem/functional/physical.hh" 684135Sgblack@eecs.umich.edu#include "sim/system.hh" 694365Sgblack@eecs.umich.edu#include "targetarch/alpha_memory.hh" 705114Sgblack@eecs.umich.edu#include "targetarch/stacktrace.hh" 715114Sgblack@eecs.umich.edu#include "targetarch/vtophys.hh" 725139Sgblack@eecs.umich.edu#else // !FULL_SYSTEM 735114Sgblack@eecs.umich.edu#include "mem/functional/functional.hh" 745139Sgblack@eecs.umich.edu#endif // FULL_SYSTEM 755139Sgblack@eecs.umich.edu 765139Sgblack@eecs.umich.eduusing namespace std; 775114Sgblack@eecs.umich.edu 785114Sgblack@eecs.umich.edu 795114Sgblack@eecs.umich.eduSimpleCPU::TickEvent::TickEvent(SimpleCPU *c, int w) 804729Sgblack@eecs.umich.edu : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c), width(w) 814365Sgblack@eecs.umich.edu{ 825114Sgblack@eecs.umich.edu} 834365Sgblack@eecs.umich.edu 844365Sgblack@eecs.umich.eduvoid 855114Sgblack@eecs.umich.eduSimpleCPU::TickEvent::process() 865114Sgblack@eecs.umich.edu{ 875114Sgblack@eecs.umich.edu int count = width; 885114Sgblack@eecs.umich.edu do { 895114Sgblack@eecs.umich.edu cpu->tick(); 905114Sgblack@eecs.umich.edu } while (--count > 0 && cpu->status() == Running); 915114Sgblack@eecs.umich.edu} 925114Sgblack@eecs.umich.edu 935114Sgblack@eecs.umich.educonst char * 945114Sgblack@eecs.umich.eduSimpleCPU::TickEvent::description() 955114Sgblack@eecs.umich.edu{ 965114Sgblack@eecs.umich.edu return "SimpleCPU tick event"; 975114Sgblack@eecs.umich.edu} 985114Sgblack@eecs.umich.edu 995114Sgblack@eecs.umich.edu 1005114Sgblack@eecs.umich.eduSimpleCPU::CacheCompletionEvent::CacheCompletionEvent(SimpleCPU *_cpu) 1015139Sgblack@eecs.umich.edu : Event(&mainEventQueue), cpu(_cpu) 1025139Sgblack@eecs.umich.edu{ 1035139Sgblack@eecs.umich.edu} 1045114Sgblack@eecs.umich.edu 1055114Sgblack@eecs.umich.eduvoid SimpleCPU::CacheCompletionEvent::process() 1065114Sgblack@eecs.umich.edu{ 1075114Sgblack@eecs.umich.edu cpu->processCacheCompletion(); 1085114Sgblack@eecs.umich.edu} 1095114Sgblack@eecs.umich.edu 1105114Sgblack@eecs.umich.educonst char * 1115114Sgblack@eecs.umich.eduSimpleCPU::CacheCompletionEvent::description() 1125139Sgblack@eecs.umich.edu{ 1135139Sgblack@eecs.umich.edu return "SimpleCPU cache completion event"; 1145139Sgblack@eecs.umich.edu} 1155114Sgblack@eecs.umich.edu 1165114Sgblack@eecs.umich.eduSimpleCPU::SimpleCPU(Params *p) 1175114Sgblack@eecs.umich.edu : BaseCPU(p), tickEvent(this, p->width), xc(NULL), 1185124Sgblack@eecs.umich.edu cacheCompletionEvent(this) 1195114Sgblack@eecs.umich.edu{ 1205114Sgblack@eecs.umich.edu _status = Idle; 1215114Sgblack@eecs.umich.edu#if FULL_SYSTEM 1225114Sgblack@eecs.umich.edu xc = new ExecContext(this, 0, p->system, p->itb, p->dtb, p->mem); 1235114Sgblack@eecs.umich.edu 1245114Sgblack@eecs.umich.edu // initialize CPU, including PC 1255114Sgblack@eecs.umich.edu TheISA::initCPU(&xc->regs); 1265139Sgblack@eecs.umich.edu#else 1275139Sgblack@eecs.umich.edu xc = new ExecContext(this, /* thread_num */ 0, p->process, /* asid */ 0); 1285139Sgblack@eecs.umich.edu#endif // !FULL_SYSTEM 1295114Sgblack@eecs.umich.edu 1305114Sgblack@eecs.umich.edu icacheInterface = p->icache_interface; 1315114Sgblack@eecs.umich.edu dcacheInterface = p->dcache_interface; 1325124Sgblack@eecs.umich.edu 1335114Sgblack@eecs.umich.edu memReq = new MemReq(); 1345114Sgblack@eecs.umich.edu memReq->xc = xc; 1355114Sgblack@eecs.umich.edu memReq->asid = 0; 1365114Sgblack@eecs.umich.edu memReq->data = new uint8_t[64]; 1375114Sgblack@eecs.umich.edu 1385114Sgblack@eecs.umich.edu numInst = 0; 1395114Sgblack@eecs.umich.edu startNumInst = 0; 1405139Sgblack@eecs.umich.edu numLoad = 0; 1415139Sgblack@eecs.umich.edu startNumLoad = 0; 1425139Sgblack@eecs.umich.edu lastIcacheStall = 0; 1435114Sgblack@eecs.umich.edu lastDcacheStall = 0; 1445114Sgblack@eecs.umich.edu 1455114Sgblack@eecs.umich.edu execContexts.push_back(xc); 1465124Sgblack@eecs.umich.edu} 1475114Sgblack@eecs.umich.edu 1484135Sgblack@eecs.umich.eduSimpleCPU::~SimpleCPU() 1494150Sgblack@eecs.umich.edu{ 1504365Sgblack@eecs.umich.edu} 1514365Sgblack@eecs.umich.edu 1524365Sgblack@eecs.umich.eduvoid 1534729Sgblack@eecs.umich.eduSimpleCPU::switchOut(Sampler *s) 1544365Sgblack@eecs.umich.edu{ 1554365Sgblack@eecs.umich.edu sampler = s; 1564365Sgblack@eecs.umich.edu if (status() == DcacheMissStall) { 1574365Sgblack@eecs.umich.edu DPRINTF(Sampler,"Outstanding dcache access, waiting for completion\n"); 1584365Sgblack@eecs.umich.edu _status = DcacheMissSwitch; 1594365Sgblack@eecs.umich.edu } 1604365Sgblack@eecs.umich.edu else { 1614365Sgblack@eecs.umich.edu _status = SwitchedOut; 1624365Sgblack@eecs.umich.edu 1634365Sgblack@eecs.umich.edu if (tickEvent.scheduled()) 1644150Sgblack@eecs.umich.edu tickEvent.squash(); 1654150Sgblack@eecs.umich.edu 1664150Sgblack@eecs.umich.edu sampler->signalSwitched(); 1674150Sgblack@eecs.umich.edu } 1685114Sgblack@eecs.umich.edu} 1695114Sgblack@eecs.umich.edu 1705114Sgblack@eecs.umich.edu 1715114Sgblack@eecs.umich.eduvoid 1725114Sgblack@eecs.umich.eduSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 1735114Sgblack@eecs.umich.edu{ 1745114Sgblack@eecs.umich.edu BaseCPU::takeOverFrom(oldCPU); 1755114Sgblack@eecs.umich.edu 1765114Sgblack@eecs.umich.edu assert(!tickEvent.scheduled()); 1775114Sgblack@eecs.umich.edu 1785114Sgblack@eecs.umich.edu // if any of this CPU's ExecContexts are active, mark the CPU as 1795114Sgblack@eecs.umich.edu // running and schedule its tick event. 1805114Sgblack@eecs.umich.edu for (int i = 0; i < execContexts.size(); ++i) { 1815114Sgblack@eecs.umich.edu ExecContext *xc = execContexts[i]; 1825114Sgblack@eecs.umich.edu if (xc->status() == ExecContext::Active && _status != Running) { 1835114Sgblack@eecs.umich.edu _status = Running; 1845114Sgblack@eecs.umich.edu tickEvent.schedule(curTick); 1855114Sgblack@eecs.umich.edu } 1865114Sgblack@eecs.umich.edu } 1875114Sgblack@eecs.umich.edu} 1885114Sgblack@eecs.umich.edu 1895114Sgblack@eecs.umich.edu 1905114Sgblack@eecs.umich.eduvoid 1915114Sgblack@eecs.umich.eduSimpleCPU::activateContext(int thread_num, int delay) 1925114Sgblack@eecs.umich.edu{ 1935114Sgblack@eecs.umich.edu assert(thread_num == 0); 1945114Sgblack@eecs.umich.edu assert(xc); 1955114Sgblack@eecs.umich.edu 1965114Sgblack@eecs.umich.edu assert(_status == Idle); 1975114Sgblack@eecs.umich.edu notIdleFraction++; 1985114Sgblack@eecs.umich.edu scheduleTickEvent(delay); 1995114Sgblack@eecs.umich.edu _status = Running; 2005114Sgblack@eecs.umich.edu} 2015114Sgblack@eecs.umich.edu 2025114Sgblack@eecs.umich.edu 2035114Sgblack@eecs.umich.eduvoid 2045114Sgblack@eecs.umich.eduSimpleCPU::suspendContext(int thread_num) 2055114Sgblack@eecs.umich.edu{ 2065114Sgblack@eecs.umich.edu assert(thread_num == 0); 2075114Sgblack@eecs.umich.edu assert(xc); 2085114Sgblack@eecs.umich.edu 2095114Sgblack@eecs.umich.edu assert(_status == Running); 2105114Sgblack@eecs.umich.edu notIdleFraction--; 2115114Sgblack@eecs.umich.edu unscheduleTickEvent(); 2125114Sgblack@eecs.umich.edu _status = Idle; 2135114Sgblack@eecs.umich.edu} 2145114Sgblack@eecs.umich.edu 2155114Sgblack@eecs.umich.edu 2165114Sgblack@eecs.umich.eduvoid 2175114Sgblack@eecs.umich.eduSimpleCPU::deallocateContext(int thread_num) 2185114Sgblack@eecs.umich.edu{ 2195114Sgblack@eecs.umich.edu // for now, these are equivalent 2205114Sgblack@eecs.umich.edu suspendContext(thread_num); 2215114Sgblack@eecs.umich.edu} 2225114Sgblack@eecs.umich.edu 2235114Sgblack@eecs.umich.edu 2245114Sgblack@eecs.umich.eduvoid 2255114Sgblack@eecs.umich.eduSimpleCPU::haltContext(int thread_num) 2265114Sgblack@eecs.umich.edu{ 2275114Sgblack@eecs.umich.edu // for now, these are equivalent 2285114Sgblack@eecs.umich.edu suspendContext(thread_num); 2295114Sgblack@eecs.umich.edu} 2305114Sgblack@eecs.umich.edu 2315114Sgblack@eecs.umich.edu 2325114Sgblack@eecs.umich.eduvoid 2335114Sgblack@eecs.umich.eduSimpleCPU::regStats() 2345114Sgblack@eecs.umich.edu{ 2355114Sgblack@eecs.umich.edu using namespace Stats; 2365114Sgblack@eecs.umich.edu 2375114Sgblack@eecs.umich.edu BaseCPU::regStats(); 2385114Sgblack@eecs.umich.edu 2395114Sgblack@eecs.umich.edu numInsts 2405114Sgblack@eecs.umich.edu .name(name() + ".num_insts") 2415114Sgblack@eecs.umich.edu .desc("Number of instructions executed") 2425114Sgblack@eecs.umich.edu ; 2435114Sgblack@eecs.umich.edu 2445114Sgblack@eecs.umich.edu numMemRefs 2455114Sgblack@eecs.umich.edu .name(name() + ".num_refs") 2465114Sgblack@eecs.umich.edu .desc("Number of memory references") 2475114Sgblack@eecs.umich.edu ; 2485114Sgblack@eecs.umich.edu 2495114Sgblack@eecs.umich.edu notIdleFraction 2505114Sgblack@eecs.umich.edu .name(name() + ".not_idle_fraction") 2515114Sgblack@eecs.umich.edu .desc("Percentage of non-idle cycles") 2525114Sgblack@eecs.umich.edu ; 2535114Sgblack@eecs.umich.edu 2545114Sgblack@eecs.umich.edu idleFraction 2555114Sgblack@eecs.umich.edu .name(name() + ".idle_fraction") 2565114Sgblack@eecs.umich.edu .desc("Percentage of idle cycles") 2575114Sgblack@eecs.umich.edu ; 2585114Sgblack@eecs.umich.edu 2595114Sgblack@eecs.umich.edu icacheStallCycles 2605114Sgblack@eecs.umich.edu .name(name() + ".icache_stall_cycles") 2615114Sgblack@eecs.umich.edu .desc("ICache total stall cycles") 2625114Sgblack@eecs.umich.edu .prereq(icacheStallCycles) 2635114Sgblack@eecs.umich.edu ; 2645114Sgblack@eecs.umich.edu 2655114Sgblack@eecs.umich.edu dcacheStallCycles 2665114Sgblack@eecs.umich.edu .name(name() + ".dcache_stall_cycles") 2675114Sgblack@eecs.umich.edu .desc("DCache total stall cycles") 2685114Sgblack@eecs.umich.edu .prereq(dcacheStallCycles) 2695114Sgblack@eecs.umich.edu ; 2705114Sgblack@eecs.umich.edu 2715114Sgblack@eecs.umich.edu idleFraction = constant(1.0) - notIdleFraction; 2725114Sgblack@eecs.umich.edu} 2735114Sgblack@eecs.umich.edu 2745114Sgblack@eecs.umich.eduvoid 2755114Sgblack@eecs.umich.eduSimpleCPU::resetStats() 2765114Sgblack@eecs.umich.edu{ 2775114Sgblack@eecs.umich.edu startNumInst = numInst; 2785114Sgblack@eecs.umich.edu notIdleFraction = (_status != Idle); 2795114Sgblack@eecs.umich.edu} 2805114Sgblack@eecs.umich.edu 2815114Sgblack@eecs.umich.eduvoid 2825114Sgblack@eecs.umich.eduSimpleCPU::serialize(ostream &os) 2835114Sgblack@eecs.umich.edu{ 2845114Sgblack@eecs.umich.edu BaseCPU::serialize(os); 2855114Sgblack@eecs.umich.edu SERIALIZE_ENUM(_status); 2865114Sgblack@eecs.umich.edu SERIALIZE_SCALAR(inst); 2875114Sgblack@eecs.umich.edu nameOut(os, csprintf("%s.xc", name())); 2885114Sgblack@eecs.umich.edu xc->serialize(os); 2895114Sgblack@eecs.umich.edu nameOut(os, csprintf("%s.tickEvent", name())); 2905114Sgblack@eecs.umich.edu tickEvent.serialize(os); 2915114Sgblack@eecs.umich.edu nameOut(os, csprintf("%s.cacheCompletionEvent", name())); 2925114Sgblack@eecs.umich.edu cacheCompletionEvent.serialize(os); 2935114Sgblack@eecs.umich.edu} 2945114Sgblack@eecs.umich.edu 2955114Sgblack@eecs.umich.eduvoid 2965114Sgblack@eecs.umich.eduSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 2975114Sgblack@eecs.umich.edu{ 2985114Sgblack@eecs.umich.edu BaseCPU::unserialize(cp, section); 2995139Sgblack@eecs.umich.edu UNSERIALIZE_ENUM(_status); 3005139Sgblack@eecs.umich.edu UNSERIALIZE_SCALAR(inst); 3015114Sgblack@eecs.umich.edu xc->unserialize(cp, csprintf("%s.xc", section)); 3025114Sgblack@eecs.umich.edu tickEvent.unserialize(cp, csprintf("%s.tickEvent", section)); 3035114Sgblack@eecs.umich.edu cacheCompletionEvent 3045114Sgblack@eecs.umich.edu .unserialize(cp, csprintf("%s.cacheCompletionEvent", section)); 3055114Sgblack@eecs.umich.edu} 3065114Sgblack@eecs.umich.edu 3075114Sgblack@eecs.umich.eduvoid 3085114Sgblack@eecs.umich.educhange_thread_state(int thread_number, int activate, int priority) 3095114Sgblack@eecs.umich.edu{ 3105114Sgblack@eecs.umich.edu} 3115114Sgblack@eecs.umich.edu 3125114Sgblack@eecs.umich.eduFault 3135114Sgblack@eecs.umich.eduSimpleCPU::copySrcTranslate(Addr src) 3145114Sgblack@eecs.umich.edu{ 3155114Sgblack@eecs.umich.edu static bool no_warn = true; 3165114Sgblack@eecs.umich.edu int blk_size = (dcacheInterface) ? dcacheInterface->getBlockSize() : 64; 3175114Sgblack@eecs.umich.edu // Only support block sizes of 64 atm. 3185114Sgblack@eecs.umich.edu assert(blk_size == 64); 3195114Sgblack@eecs.umich.edu int offset = src & (blk_size - 1); 3205114Sgblack@eecs.umich.edu 3215114Sgblack@eecs.umich.edu // Make sure block doesn't span page 3225114Sgblack@eecs.umich.edu if (no_warn && 3235114Sgblack@eecs.umich.edu (src & TheISA::PageMask) != ((src + blk_size) & TheISA::PageMask) && 3245114Sgblack@eecs.umich.edu (src >> 40) != 0xfffffc) { 3255114Sgblack@eecs.umich.edu warn("Copied block source spans pages %x.", src); 3265114Sgblack@eecs.umich.edu no_warn = false; 3275114Sgblack@eecs.umich.edu } 3285114Sgblack@eecs.umich.edu 3295114Sgblack@eecs.umich.edu memReq->reset(src & ~(blk_size - 1), blk_size); 3305114Sgblack@eecs.umich.edu 3315114Sgblack@eecs.umich.edu // translate to physical address 3325114Sgblack@eecs.umich.edu Fault fault = xc->translateDataReadReq(memReq); 3335114Sgblack@eecs.umich.edu 3345114Sgblack@eecs.umich.edu assert(fault != Alignment_Fault); 3355114Sgblack@eecs.umich.edu 3365114Sgblack@eecs.umich.edu if (fault == No_Fault) { 3375114Sgblack@eecs.umich.edu xc->copySrcAddr = src; 3385114Sgblack@eecs.umich.edu xc->copySrcPhysAddr = memReq->paddr + offset; 3395114Sgblack@eecs.umich.edu } else { 3405114Sgblack@eecs.umich.edu xc->copySrcAddr = 0; 3415114Sgblack@eecs.umich.edu xc->copySrcPhysAddr = 0; 3425114Sgblack@eecs.umich.edu } 3435114Sgblack@eecs.umich.edu return fault; 3445114Sgblack@eecs.umich.edu} 3455114Sgblack@eecs.umich.edu 3465114Sgblack@eecs.umich.eduFault 3475114Sgblack@eecs.umich.eduSimpleCPU::copy(Addr dest) 3485114Sgblack@eecs.umich.edu{ 3495114Sgblack@eecs.umich.edu static bool no_warn = true; 3505114Sgblack@eecs.umich.edu int blk_size = (dcacheInterface) ? dcacheInterface->getBlockSize() : 64; 3515114Sgblack@eecs.umich.edu // Only support block sizes of 64 atm. 3525114Sgblack@eecs.umich.edu assert(blk_size == 64); 3535114Sgblack@eecs.umich.edu uint8_t data[blk_size]; 3545114Sgblack@eecs.umich.edu //assert(xc->copySrcAddr); 3555114Sgblack@eecs.umich.edu int offset = dest & (blk_size - 1); 3565114Sgblack@eecs.umich.edu 3575114Sgblack@eecs.umich.edu // Make sure block doesn't span page 3585114Sgblack@eecs.umich.edu if (no_warn && 3595114Sgblack@eecs.umich.edu (dest & TheISA::PageMask) != ((dest + blk_size) & TheISA::PageMask) && 3605114Sgblack@eecs.umich.edu (dest >> 40) != 0xfffffc) { 3615114Sgblack@eecs.umich.edu no_warn = false; 3625114Sgblack@eecs.umich.edu warn("Copied block destination spans pages %x. ", dest); 3635114Sgblack@eecs.umich.edu } 3645114Sgblack@eecs.umich.edu 3655114Sgblack@eecs.umich.edu memReq->reset(dest & ~(blk_size -1), blk_size); 3665114Sgblack@eecs.umich.edu // translate to physical address 3675114Sgblack@eecs.umich.edu Fault fault = xc->translateDataWriteReq(memReq); 3685114Sgblack@eecs.umich.edu 3695114Sgblack@eecs.umich.edu assert(fault != Alignment_Fault); 3705114Sgblack@eecs.umich.edu 3715114Sgblack@eecs.umich.edu if (fault == No_Fault) { 3725124Sgblack@eecs.umich.edu Addr dest_addr = memReq->paddr + offset; 3735124Sgblack@eecs.umich.edu // Need to read straight from memory since we have more than 8 bytes. 3745124Sgblack@eecs.umich.edu memReq->paddr = xc->copySrcPhysAddr; 3755124Sgblack@eecs.umich.edu xc->mem->read(memReq, data); 3765124Sgblack@eecs.umich.edu memReq->paddr = dest_addr; 3775124Sgblack@eecs.umich.edu xc->mem->write(memReq, data); 3785114Sgblack@eecs.umich.edu if (dcacheInterface) { 3795124Sgblack@eecs.umich.edu memReq->cmd = Copy; 3805124Sgblack@eecs.umich.edu memReq->completionEvent = NULL; 3815114Sgblack@eecs.umich.edu memReq->paddr = xc->copySrcPhysAddr; 3825114Sgblack@eecs.umich.edu memReq->dest = dest_addr; 3835114Sgblack@eecs.umich.edu memReq->size = 64; 3845114Sgblack@eecs.umich.edu memReq->time = curTick; 3855124Sgblack@eecs.umich.edu dcacheInterface->access(memReq); 3865124Sgblack@eecs.umich.edu } 3875124Sgblack@eecs.umich.edu } 3885124Sgblack@eecs.umich.edu return fault; 3895124Sgblack@eecs.umich.edu} 3905124Sgblack@eecs.umich.edu 3915114Sgblack@eecs.umich.edu// precise architected memory state accessor macros 3925124Sgblack@eecs.umich.edutemplate <class T> 3935124Sgblack@eecs.umich.eduFault 3945114Sgblack@eecs.umich.eduSimpleCPU::read(Addr addr, T &data, unsigned flags) 3954120Sgblack@eecs.umich.edu{ 3964120Sgblack@eecs.umich.edu if (status() == DcacheMissStall || status() == DcacheMissSwitch) { 3974120Sgblack@eecs.umich.edu Fault fault = xc->read(memReq,data); 398 399 if (traceData) { 400 traceData->setAddr(addr); 401 } 402 return fault; 403 } 404 405 memReq->reset(addr, sizeof(T), flags); 406 407 // translate to physical address 408 Fault fault = xc->translateDataReadReq(memReq); 409 410 // if we have a cache, do cache access too 411 if (fault == No_Fault && dcacheInterface) { 412 memReq->cmd = Read; 413 memReq->completionEvent = NULL; 414 memReq->time = curTick; 415 MemAccessResult result = dcacheInterface->access(memReq); 416 417 // Ugly hack to get an event scheduled *only* if the access is 418 // a miss. We really should add first-class support for this 419 // at some point. 420 if (result != MA_HIT && dcacheInterface->doEvents()) { 421 memReq->completionEvent = &cacheCompletionEvent; 422 lastDcacheStall = curTick; 423 unscheduleTickEvent(); 424 _status = DcacheMissStall; 425 } else { 426 // do functional access 427 fault = xc->read(memReq, data); 428 429 } 430 } else if(fault == No_Fault) { 431 // do functional access 432 fault = xc->read(memReq, data); 433 434 } 435 436 if (!dcacheInterface && (memReq->flags & UNCACHEABLE)) 437 recordEvent("Uncached Read"); 438 439 return fault; 440} 441 442#ifndef DOXYGEN_SHOULD_SKIP_THIS 443 444template 445Fault 446SimpleCPU::read(Addr addr, uint64_t &data, unsigned flags); 447 448template 449Fault 450SimpleCPU::read(Addr addr, uint32_t &data, unsigned flags); 451 452template 453Fault 454SimpleCPU::read(Addr addr, uint16_t &data, unsigned flags); 455 456template 457Fault 458SimpleCPU::read(Addr addr, uint8_t &data, unsigned flags); 459 460#endif //DOXYGEN_SHOULD_SKIP_THIS 461 462template<> 463Fault 464SimpleCPU::read(Addr addr, double &data, unsigned flags) 465{ 466 return read(addr, *(uint64_t*)&data, flags); 467} 468 469template<> 470Fault 471SimpleCPU::read(Addr addr, float &data, unsigned flags) 472{ 473 return read(addr, *(uint32_t*)&data, flags); 474} 475 476 477template<> 478Fault 479SimpleCPU::read(Addr addr, int32_t &data, unsigned flags) 480{ 481 return read(addr, (uint32_t&)data, flags); 482} 483 484 485template <class T> 486Fault 487SimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res) 488{ 489 memReq->reset(addr, sizeof(T), flags); 490 491 // translate to physical address 492 Fault fault = xc->translateDataWriteReq(memReq); 493 494 // do functional access 495 if (fault == No_Fault) 496 fault = xc->write(memReq, data); 497 498 if (fault == No_Fault && dcacheInterface) { 499 memReq->cmd = Write; 500 memcpy(memReq->data,(uint8_t *)&data,memReq->size); 501 memReq->completionEvent = NULL; 502 memReq->time = curTick; 503 MemAccessResult result = dcacheInterface->access(memReq); 504 505 // Ugly hack to get an event scheduled *only* if the access is 506 // a miss. We really should add first-class support for this 507 // at some point. 508 if (result != MA_HIT && dcacheInterface->doEvents()) { 509 memReq->completionEvent = &cacheCompletionEvent; 510 lastDcacheStall = curTick; 511 unscheduleTickEvent(); 512 _status = DcacheMissStall; 513 } 514 } 515 516 if (res && (fault == No_Fault)) 517 *res = memReq->result; 518 519 if (!dcacheInterface && (memReq->flags & UNCACHEABLE)) 520 recordEvent("Uncached Write"); 521 522 return fault; 523} 524 525 526#ifndef DOXYGEN_SHOULD_SKIP_THIS 527template 528Fault 529SimpleCPU::write(uint64_t data, Addr addr, unsigned flags, uint64_t *res); 530 531template 532Fault 533SimpleCPU::write(uint32_t data, Addr addr, unsigned flags, uint64_t *res); 534 535template 536Fault 537SimpleCPU::write(uint16_t data, Addr addr, unsigned flags, uint64_t *res); 538 539template 540Fault 541SimpleCPU::write(uint8_t data, Addr addr, unsigned flags, uint64_t *res); 542 543#endif //DOXYGEN_SHOULD_SKIP_THIS 544 545template<> 546Fault 547SimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res) 548{ 549 return write(*(uint64_t*)&data, addr, flags, res); 550} 551 552template<> 553Fault 554SimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res) 555{ 556 return write(*(uint32_t*)&data, addr, flags, res); 557} 558 559 560template<> 561Fault 562SimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res) 563{ 564 return write((uint32_t)data, addr, flags, res); 565} 566 567 568#if FULL_SYSTEM 569Addr 570SimpleCPU::dbg_vtophys(Addr addr) 571{ 572 return vtophys(xc, addr); 573} 574#endif // FULL_SYSTEM 575 576void 577SimpleCPU::processCacheCompletion() 578{ 579 switch (status()) { 580 case IcacheMissStall: 581 icacheStallCycles += curTick - lastIcacheStall; 582 _status = IcacheMissComplete; 583 scheduleTickEvent(1); 584 break; 585 case DcacheMissStall: 586 if (memReq->cmd.isRead()) { 587 curStaticInst->execute(this,traceData); 588 if (traceData) 589 traceData->finalize(); 590 } 591 dcacheStallCycles += curTick - lastDcacheStall; 592 _status = Running; 593 scheduleTickEvent(1); 594 break; 595 case DcacheMissSwitch: 596 if (memReq->cmd.isRead()) { 597 curStaticInst->execute(this,traceData); 598 if (traceData) 599 traceData->finalize(); 600 } 601 _status = SwitchedOut; 602 sampler->signalSwitched(); 603 case SwitchedOut: 604 // If this CPU has been switched out due to sampling/warm-up, 605 // ignore any further status changes (e.g., due to cache 606 // misses outstanding at the time of the switch). 607 return; 608 default: 609 panic("SimpleCPU::processCacheCompletion: bad state"); 610 break; 611 } 612} 613 614#if FULL_SYSTEM 615void 616SimpleCPU::post_interrupt(int int_num, int index) 617{ 618 BaseCPU::post_interrupt(int_num, index); 619 620 if (xc->status() == ExecContext::Suspended) { 621 DPRINTF(IPI,"Suspended Processor awoke\n"); 622 xc->activate(); 623 } 624} 625#endif // FULL_SYSTEM 626 627/* start simulation, program loaded, processor precise state initialized */ 628void 629SimpleCPU::tick() 630{ 631 numCycles++; 632 633 traceData = NULL; 634 635 Fault fault = No_Fault; 636 637#if FULL_SYSTEM 638 if (checkInterrupts && check_interrupts() && !xc->inPalMode() && 639 status() != IcacheMissComplete) { 640 int ipl = 0; 641 int summary = 0; 642 checkInterrupts = false; 643 IntReg *ipr = xc->regs.ipr; 644 645 if (xc->regs.ipr[TheISA::IPR_SIRR]) { 646 for (int i = TheISA::INTLEVEL_SOFTWARE_MIN; 647 i < TheISA::INTLEVEL_SOFTWARE_MAX; i++) { 648 if (ipr[TheISA::IPR_SIRR] & (ULL(1) << i)) { 649 // See table 4-19 of 21164 hardware reference 650 ipl = (i - TheISA::INTLEVEL_SOFTWARE_MIN) + 1; 651 summary |= (ULL(1) << i); 652 } 653 } 654 } 655 656 uint64_t interrupts = xc->cpu->intr_status(); 657 for (int i = TheISA::INTLEVEL_EXTERNAL_MIN; 658 i < TheISA::INTLEVEL_EXTERNAL_MAX; i++) { 659 if (interrupts & (ULL(1) << i)) { 660 // See table 4-19 of 21164 hardware reference 661 ipl = i; 662 summary |= (ULL(1) << i); 663 } 664 } 665 666 if (ipr[TheISA::IPR_ASTRR]) 667 panic("asynchronous traps not implemented\n"); 668 669 if (ipl && ipl > xc->regs.ipr[TheISA::IPR_IPLR]) { 670 ipr[TheISA::IPR_ISR] = summary; 671 ipr[TheISA::IPR_INTID] = ipl; 672 xc->ev5_trap(Interrupt_Fault); 673 674 DPRINTF(Flow, "Interrupt! IPLR=%d ipl=%d summary=%x\n", 675 ipr[TheISA::IPR_IPLR], ipl, summary); 676 } 677 } 678#endif 679 680 // maintain $r0 semantics 681 xc->regs.intRegFile[ZeroReg] = 0; 682#ifdef TARGET_ALPHA 683 xc->regs.floatRegFile.d[ZeroReg] = 0.0; 684#endif // TARGET_ALPHA 685 686 if (status() == IcacheMissComplete) { 687 // We've already fetched an instruction and were stalled on an 688 // I-cache miss. No need to fetch it again. 689 690 // Set status to running; tick event will get rescheduled if 691 // necessary at end of tick() function. 692 _status = Running; 693 } 694 else { 695 // Try to fetch an instruction 696 697 // set up memory request for instruction fetch 698#if FULL_SYSTEM 699#define IFETCH_FLAGS(pc) ((pc) & 1) ? PHYSICAL : 0 700#else 701#define IFETCH_FLAGS(pc) 0 702#endif 703 704 memReq->cmd = Read; 705 memReq->reset(xc->regs.pc & ~3, sizeof(uint32_t), 706 IFETCH_FLAGS(xc->regs.pc)); 707 708 fault = xc->translateInstReq(memReq); 709 710 if (fault == No_Fault) 711 fault = xc->mem->read(memReq, inst); 712 713 if (icacheInterface && fault == No_Fault) { 714 memReq->completionEvent = NULL; 715 716 memReq->time = curTick; 717 MemAccessResult result = icacheInterface->access(memReq); 718 719 // Ugly hack to get an event scheduled *only* if the access is 720 // a miss. We really should add first-class support for this 721 // at some point. 722 if (result != MA_HIT && icacheInterface->doEvents()) { 723 memReq->completionEvent = &cacheCompletionEvent; 724 lastIcacheStall = curTick; 725 unscheduleTickEvent(); 726 _status = IcacheMissStall; 727 return; 728 } 729 } 730 } 731 732 // If we've got a valid instruction (i.e., no fault on instruction 733 // fetch), then execute it. 734 if (fault == No_Fault) { 735 736 // keep an instruction count 737 numInst++; 738 numInsts++; 739 740 // check for instruction-count-based events 741 comInstEventQueue[0]->serviceEvents(numInst); 742 743 // decode the instruction 744 inst = gtoh(inst); 745 curStaticInst = StaticInst<TheISA>::decode(inst); 746 747 traceData = Trace::getInstRecord(curTick, xc, this, curStaticInst, 748 xc->regs.pc); 749 750#if FULL_SYSTEM 751 xc->setInst(inst); 752#endif // FULL_SYSTEM 753 754 xc->func_exe_inst++; 755 756 fault = curStaticInst->execute(this, traceData); 757 758#if FULL_SYSTEM 759 if (xc->fnbin) { 760 assert(xc->kernelStats); 761 system->kernelBinning->execute(xc, inst); 762 } 763 764 if (xc->profile) { 765 bool usermode = (xc->regs.ipr[AlphaISA::IPR_DTB_CM] & 0x18) != 0; 766 xc->profilePC = usermode ? 1 : xc->regs.pc; 767 xc->profileNode = xc->profile->consume(xc, inst); 768 } 769#endif 770 771 if (curStaticInst->isMemRef()) { 772 numMemRefs++; 773 } 774 775 if (curStaticInst->isLoad()) { 776 ++numLoad; 777 comLoadEventQueue[0]->serviceEvents(numLoad); 778 } 779 780 // If we have a dcache miss, then we can't finialize the instruction 781 // trace yet because we want to populate it with the data later 782 if (traceData && 783 !(status() == DcacheMissStall && memReq->cmd.isRead())) { 784 traceData->finalize(); 785 } 786 787 traceFunctions(xc->regs.pc); 788 789 } // if (fault == No_Fault) 790 791 if (fault != No_Fault) { 792#if FULL_SYSTEM 793 xc->ev5_trap(fault); 794#else // !FULL_SYSTEM 795 fatal("fault (%d) detected @ PC 0x%08p", fault, xc->regs.pc); 796#endif // FULL_SYSTEM 797 } 798 else { 799 // go to the next instruction 800 xc->regs.pc = xc->regs.npc; 801 xc->regs.npc += sizeof(MachInst); 802 } 803 804#if FULL_SYSTEM 805 Addr oldpc; 806 do { 807 oldpc = xc->regs.pc; 808 system->pcEventQueue.service(xc); 809 } while (oldpc != xc->regs.pc); 810#endif 811 812 assert(status() == Running || 813 status() == Idle || 814 status() == DcacheMissStall); 815 816 if (status() == Running && !tickEvent.scheduled()) 817 tickEvent.schedule(curTick + cycles(1)); 818} 819 820//////////////////////////////////////////////////////////////////////// 821// 822// SimpleCPU Simulation Object 823// 824BEGIN_DECLARE_SIM_OBJECT_PARAMS(SimpleCPU) 825 826 Param<Counter> max_insts_any_thread; 827 Param<Counter> max_insts_all_threads; 828 Param<Counter> max_loads_any_thread; 829 Param<Counter> max_loads_all_threads; 830 831#if FULL_SYSTEM 832 SimObjectParam<AlphaITB *> itb; 833 SimObjectParam<AlphaDTB *> dtb; 834 SimObjectParam<FunctionalMemory *> mem; 835 SimObjectParam<System *> system; 836 Param<int> cpu_id; 837 Param<Tick> profile; 838#else 839 SimObjectParam<Process *> workload; 840#endif // FULL_SYSTEM 841 842 Param<int> clock; 843 SimObjectParam<BaseMem *> icache; 844 SimObjectParam<BaseMem *> dcache; 845 846 Param<bool> defer_registration; 847 Param<int> width; 848 Param<bool> function_trace; 849 Param<Tick> function_trace_start; 850 851END_DECLARE_SIM_OBJECT_PARAMS(SimpleCPU) 852 853BEGIN_INIT_SIM_OBJECT_PARAMS(SimpleCPU) 854 855 INIT_PARAM(max_insts_any_thread, 856 "terminate when any thread reaches this inst count"), 857 INIT_PARAM(max_insts_all_threads, 858 "terminate when all threads have reached this inst count"), 859 INIT_PARAM(max_loads_any_thread, 860 "terminate when any thread reaches this load count"), 861 INIT_PARAM(max_loads_all_threads, 862 "terminate when all threads have reached this load count"), 863 864#if FULL_SYSTEM 865 INIT_PARAM(itb, "Instruction TLB"), 866 INIT_PARAM(dtb, "Data TLB"), 867 INIT_PARAM(mem, "memory"), 868 INIT_PARAM(system, "system object"), 869 INIT_PARAM(cpu_id, "processor ID"), 870 INIT_PARAM(profile, ""), 871#else 872 INIT_PARAM(workload, "processes to run"), 873#endif // FULL_SYSTEM 874 875 INIT_PARAM(clock, "clock speed"), 876 INIT_PARAM(icache, "L1 instruction cache object"), 877 INIT_PARAM(dcache, "L1 data cache object"), 878 INIT_PARAM(defer_registration, "defer system registration (for sampling)"), 879 INIT_PARAM(width, "cpu width"), 880 INIT_PARAM(function_trace, "Enable function trace"), 881 INIT_PARAM(function_trace_start, "Cycle to start function trace") 882 883END_INIT_SIM_OBJECT_PARAMS(SimpleCPU) 884 885 886CREATE_SIM_OBJECT(SimpleCPU) 887{ 888 SimpleCPU::Params *params = new SimpleCPU::Params(); 889 params->name = getInstanceName(); 890 params->numberOfThreads = 1; 891 params->max_insts_any_thread = max_insts_any_thread; 892 params->max_insts_all_threads = max_insts_all_threads; 893 params->max_loads_any_thread = max_loads_any_thread; 894 params->max_loads_all_threads = max_loads_all_threads; 895 params->deferRegistration = defer_registration; 896 params->clock = clock; 897 params->functionTrace = function_trace; 898 params->functionTraceStart = function_trace_start; 899 params->icache_interface = (icache) ? icache->getInterface() : NULL; 900 params->dcache_interface = (dcache) ? dcache->getInterface() : NULL; 901 params->width = width; 902 903#if FULL_SYSTEM 904 params->itb = itb; 905 params->dtb = dtb; 906 params->mem = mem; 907 params->system = system; 908 params->cpu_id = cpu_id; 909 params->profile = profile; 910#else 911 params->process = workload; 912#endif 913 914 SimpleCPU *cpu = new SimpleCPU(params); 915 return cpu; 916} 917 918REGISTER_SIM_OBJECT("SimpleCPU", SimpleCPU) 919 920