base.hh revision 1400
12SN/A/* 29448SAndreas.Sandberg@ARM.com * Copyright (c) 2002-2004 The Regents of The University of Michigan 39920Syasuko.eckert@amd.com * All rights reserved. 48733Sgeoffrey.blake@arm.com * 58733Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without 68733Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are 78733Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright 88733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer; 98733Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright 108733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the 118733Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution; 128733Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its 138733Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from 148733Sgeoffrey.blake@arm.com * this software without specific prior written permission. 151762SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A */ 282SN/A 292SN/A#ifndef __CPU_SIMPLE_CPU_SIMPLE_CPU_HH__ 302SN/A#define __CPU_SIMPLE_CPU_SIMPLE_CPU_HH__ 312SN/A 322SN/A#include "base/statistics.hh" 332SN/A#include "cpu/base_cpu.hh" 342SN/A#include "cpu/exec_context.hh" 352SN/A#include "cpu/pc_event.hh" 362SN/A#include "cpu/static_inst.hh" 372SN/A#include "sim/eventq.hh" 382SN/A 392SN/A// forward declarations 402665Ssaidi@eecs.umich.edu#ifdef FULL_SYSTEM 412665Ssaidi@eecs.umich.educlass Processor; 422665Ssaidi@eecs.umich.educlass AlphaITB; 432665Ssaidi@eecs.umich.educlass AlphaDTB; 442SN/Aclass PhysicalMemory; 452SN/A 462623SN/Aclass RemoteGDB; 472623SN/Aclass GDBListener; 482SN/A 491354SN/A#else 506658Snate@binkert.org 511717SN/Aclass Process; 528887Sgeoffrey.blake@arm.com 538229Snate@binkert.org#endif // FULL_SYSTEM 542683Sktlim@umich.edu 551354SN/Aclass MemInterface; 562387SN/Aclass Checkpoint; 572387SN/A 582387SN/Anamespace Trace { 5956SN/A class InstRecord; 608779Sgblack@eecs.umich.edu} 615348Ssaidi@eecs.umich.edu 622SN/Aclass SimpleCPU : public BaseCPU 632SN/A{ 648779Sgblack@eecs.umich.edu public: 658779Sgblack@eecs.umich.edu // main simulation loop (one cycle) 662SN/A void tick(); 678779Sgblack@eecs.umich.edu 682SN/A private: 694182Sgblack@eecs.umich.edu struct TickEvent : public Event 704182Sgblack@eecs.umich.edu { 718779Sgblack@eecs.umich.edu SimpleCPU *cpu; 728779Sgblack@eecs.umich.edu int width; 734182Sgblack@eecs.umich.edu 742SN/A TickEvent(SimpleCPU *c, int w); 752SN/A void process(); 762SN/A const char *description(); 772SN/A }; 782SN/A 798737Skoansin.tan@gmail.com TickEvent tickEvent; 805529Snate@binkert.org 812420SN/A /// Schedule tick event, regardless of its current state. 822623SN/A void scheduleTickEvent(int delay) 832SN/A { 842107SN/A if (tickEvent.squashed()) 852159SN/A tickEvent.reschedule(curTick + delay); 862455SN/A else if (!tickEvent.scheduled()) 872455SN/A tickEvent.schedule(curTick + delay); 889920Syasuko.eckert@amd.com } 892386SN/A 902623SN/A /// Unschedule tick event, regardless of its current state. 912SN/A void unscheduleTickEvent() 921371SN/A { 935348Ssaidi@eecs.umich.edu if (tickEvent.scheduled()) 947720Sgblack@eecs.umich.edu tickEvent.squash(); 955348Ssaidi@eecs.umich.edu } 967720Sgblack@eecs.umich.edu 975348Ssaidi@eecs.umich.edu private: 987720Sgblack@eecs.umich.edu Trace::InstRecord *traceData; 997720Sgblack@eecs.umich.edu 1005348Ssaidi@eecs.umich.edu public: 1015348Ssaidi@eecs.umich.edu // 1022SN/A enum Status { 1035807Snate@binkert.org Running, 1042SN/A Idle, 1052SN/A IcacheMissStall, 1062SN/A IcacheMissComplete, 1072SN/A DcacheMissStall, 1082SN/A SwitchedOut 1092SN/A }; 1102SN/A 1112SN/A private: 1122SN/A Status _status; 1131400SN/A 1145529Snate@binkert.org public: 1152623SN/A void post_interrupt(int int_num, int index); 1162SN/A 1171400SN/A void zero_fill_64(Addr addr) { 1182683Sktlim@umich.edu static int warned = 0; 1192683Sktlim@umich.edu if (!warned) { 1202190SN/A warn ("WH64 is not implemented"); 1212683Sktlim@umich.edu warned = 1; 1222683Sktlim@umich.edu } 1232683Sktlim@umich.edu }; 1242680Sktlim@umich.edu 1258733Sgeoffrey.blake@arm.com public: 1268733Sgeoffrey.blake@arm.com struct Params : public BaseCPU::Params 1278887Sgeoffrey.blake@arm.com { 1285169Ssaidi@eecs.umich.edu MemInterface *icache_interface; 1295169Ssaidi@eecs.umich.edu MemInterface *dcache_interface; 1305496Ssaidi@eecs.umich.edu int width; 1315496Ssaidi@eecs.umich.edu#ifdef FULL_SYSTEM 1325496Ssaidi@eecs.umich.edu AlphaITB *itb; 1338276SAli.Saidi@ARM.com AlphaDTB *dtb; 1345894Sgblack@eecs.umich.edu FunctionalMemory *mem; 1355496Ssaidi@eecs.umich.edu#else 1365496Ssaidi@eecs.umich.edu Process *process; 1375496Ssaidi@eecs.umich.edu#endif 1385894Sgblack@eecs.umich.edu }; 1395496Ssaidi@eecs.umich.edu SimpleCPU(Params *params); 1405496Ssaidi@eecs.umich.edu virtual ~SimpleCPU(); 1415496Ssaidi@eecs.umich.edu 1425496Ssaidi@eecs.umich.edu public: 1435496Ssaidi@eecs.umich.edu // execution context 1445496Ssaidi@eecs.umich.edu ExecContext *xc; 1455496Ssaidi@eecs.umich.edu 1465169Ssaidi@eecs.umich.edu void switchOut(); 1472SN/A void takeOverFrom(BaseCPU *oldCPU); 1482SN/A 1492SN/A#ifdef FULL_SYSTEM 1502SN/A Addr dbg_vtophys(Addr addr); 1512SN/A 1522SN/A bool interval_stats; 1534181Sgblack@eecs.umich.edu#endif 1544181Sgblack@eecs.umich.edu 1552107SN/A // L1 instruction cache 1563276Sgblack@eecs.umich.edu MemInterface *icacheInterface; 1571469SN/A 1584377Sgblack@eecs.umich.edu // L1 data cache 1594377Sgblack@eecs.umich.edu MemInterface *dcacheInterface; 1604377Sgblack@eecs.umich.edu 1614377Sgblack@eecs.umich.edu // current instruction 1624377Sgblack@eecs.umich.edu MachInst inst; 1634377Sgblack@eecs.umich.edu 1642623SN/A // Refcounted pointer to the one memory request. 1655894Sgblack@eecs.umich.edu MemReqPtr memReq; 1662623SN/A 1672623SN/A class CacheCompletionEvent : public Event 1682623SN/A { 169180SN/A private: 1708737Skoansin.tan@gmail.com SimpleCPU *cpu; 1718737Skoansin.tan@gmail.com 1722SN/A public: 1732SN/A CacheCompletionEvent(SimpleCPU *_cpu); 174334SN/A 175334SN/A virtual void process(); 1762SN/A virtual const char *description(); 1779461Snilay@cs.wisc.edu }; 1789461Snilay@cs.wisc.edu 1792SN/A CacheCompletionEvent cacheCompletionEvent; 1802SN/A 181334SN/A Status status() const { return _status; } 1825999Snate@binkert.org 1838834Satgutier@umich.edu virtual void activateContext(int thread_num, int delay); 1848834Satgutier@umich.edu virtual void suspendContext(int thread_num); 1858834Satgutier@umich.edu virtual void deallocateContext(int thread_num); 186707SN/A virtual void haltContext(int thread_num); 1874998Sgblack@eecs.umich.edu 1884998Sgblack@eecs.umich.edu // statistics 1898834Satgutier@umich.edu virtual void regStats(); 1908834Satgutier@umich.edu virtual void resetStats(); 1918834Satgutier@umich.edu 1928834Satgutier@umich.edu // number of simulated instructions 1938834Satgutier@umich.edu Counter numInst; 1948834Satgutier@umich.edu Counter startNumInst; 1958834Satgutier@umich.edu Stats::Scalar<> numInsts; 1967897Shestness@cs.utexas.edu 1974998Sgblack@eecs.umich.edu virtual Counter totalInstructions() const 1984998Sgblack@eecs.umich.edu { 1994998Sgblack@eecs.umich.edu return numInst - startNumInst; 2008834Satgutier@umich.edu } 201707SN/A 202707SN/A // number of simulated memory references 203707SN/A Stats::Scalar<> numMemRefs; 2042SN/A 2058834Satgutier@umich.edu // number of simulated loads 2068834Satgutier@umich.edu Counter numLoad; 2078834Satgutier@umich.edu Counter startNumLoad; 2088834Satgutier@umich.edu 2098834Satgutier@umich.edu // number of idle cycles 2107897Shestness@cs.utexas.edu Stats::Average<> notIdleFraction; 2117897Shestness@cs.utexas.edu Stats::Formula idleFraction; 2127897Shestness@cs.utexas.edu 2137897Shestness@cs.utexas.edu // number of cycles stalled for I-cache misses 2147897Shestness@cs.utexas.edu Stats::Scalar<> icacheStallCycles; 2157897Shestness@cs.utexas.edu Counter lastIcacheStall; 2167897Shestness@cs.utexas.edu 2177897Shestness@cs.utexas.edu // number of cycles stalled for D-cache misses 2187897Shestness@cs.utexas.edu Stats::Scalar<> dcacheStallCycles; 2197897Shestness@cs.utexas.edu Counter lastDcacheStall; 2207897Shestness@cs.utexas.edu 2217897Shestness@cs.utexas.edu void processCacheCompletion(); 2227897Shestness@cs.utexas.edu 2237897Shestness@cs.utexas.edu virtual void serialize(std::ostream &os); 2247897Shestness@cs.utexas.edu virtual void unserialize(Checkpoint *cp, const std::string §ion); 2257897Shestness@cs.utexas.edu 2267897Shestness@cs.utexas.edu template <class T> 2277897Shestness@cs.utexas.edu Fault read(Addr addr, T &data, unsigned flags); 2287897Shestness@cs.utexas.edu 2297897Shestness@cs.utexas.edu template <class T> 2307897Shestness@cs.utexas.edu Fault write(T data, Addr addr, unsigned flags, uint64_t *res); 2317897Shestness@cs.utexas.edu 2327897Shestness@cs.utexas.edu // These functions are only used in CPU models that split 2337897Shestness@cs.utexas.edu // effective address computation from the actual memory access. 2347897Shestness@cs.utexas.edu void setEA(Addr EA) { panic("SimpleCPU::setEA() not implemented\n"); } 2357897Shestness@cs.utexas.edu Addr getEA() { panic("SimpleCPU::getEA() not implemented\n"); } 2369920Syasuko.eckert@amd.com 2379920Syasuko.eckert@amd.com void prefetch(Addr addr, unsigned flags) 2389920Syasuko.eckert@amd.com { 2399920Syasuko.eckert@amd.com // need to do this... 2402SN/A } 2415999Snate@binkert.org 2427897Shestness@cs.utexas.edu void writeHint(Addr addr, int size, unsigned flags) 2437897Shestness@cs.utexas.edu { 2447897Shestness@cs.utexas.edu // need to do this... 2457897Shestness@cs.utexas.edu } 2467897Shestness@cs.utexas.edu 2477897Shestness@cs.utexas.edu Fault copySrcTranslate(Addr src); 2487897Shestness@cs.utexas.edu 2497897Shestness@cs.utexas.edu Fault copy(Addr dest); 2502SN/A 251124SN/A // The register accessor methods provide the index of the 252124SN/A // instruction's operand (e.g., 0 or 1), not the architectural 253334SN/A // register index, to simplify the implementation of register 254124SN/A // renaming. We find the architectural register index by indexing 2552SN/A // into the instruction's own operand index table. Note that a 2565999Snate@binkert.org // raw pointer to the StaticInst is provided instead of a 257729SN/A // ref-counted StaticInstPtr to redice overhead. This is fine as 2582SN/A // long as these methods don't copy the pointer into any long-term 2592390SN/A // storage (which is pretty hard to imagine they would have reason 2605999Snate@binkert.org // to do). 2612SN/A 2622SN/A uint64_t readIntReg(StaticInst<TheISA> *si, int idx) 2632390SN/A { 2645999Snate@binkert.org return xc->readIntReg(si->srcRegIdx(idx)); 2652390SN/A } 2662390SN/A 2672390SN/A float readFloatRegSingle(StaticInst<TheISA> *si, int idx) 2685999Snate@binkert.org { 2692SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2702SN/A return xc->readFloatRegSingle(reg_idx); 2712390SN/A } 2725999Snate@binkert.org 2732390SN/A double readFloatRegDouble(StaticInst<TheISA> *si, int idx) 2742390SN/A { 2759448SAndreas.Sandberg@ARM.com int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2769448SAndreas.Sandberg@ARM.com return xc->readFloatRegDouble(reg_idx); 2779448SAndreas.Sandberg@ARM.com } 2782SN/A 2791371SN/A uint64_t readFloatRegInt(StaticInst<TheISA> *si, int idx) 2801371SN/A { 2812623SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2825543Ssaidi@eecs.umich.edu return xc->readFloatRegInt(reg_idx); 2833918Ssaidi@eecs.umich.edu } 2841371SN/A 285726SN/A void setIntReg(StaticInst<TheISA> *si, int idx, uint64_t val) 286726SN/A { 287726SN/A xc->setIntReg(si->destRegIdx(idx), val); 288726SN/A } 289726SN/A 290726SN/A void setFloatRegSingle(StaticInst<TheISA> *si, int idx, float val) 291726SN/A { 292726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 293726SN/A xc->setFloatRegSingle(reg_idx, val); 294726SN/A } 295705SN/A 2963735Sstever@eecs.umich.edu void setFloatRegDouble(StaticInst<TheISA> *si, int idx, double val) 297726SN/A { 2987897Shestness@cs.utexas.edu int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2992683Sktlim@umich.edu xc->setFloatRegDouble(reg_idx, val); 300726SN/A } 301705SN/A 3023735Sstever@eecs.umich.edu void setFloatRegInt(StaticInst<TheISA> *si, int idx, uint64_t val) 303726SN/A { 3047897Shestness@cs.utexas.edu int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3059918Ssteve.reinhardt@amd.com xc->setFloatRegInt(reg_idx, val); 3062683Sktlim@umich.edu } 307726SN/A 308705SN/A uint64_t readPC() { return xc->readPC(); } 3093735Sstever@eecs.umich.edu void setNextPC(uint64_t val) { xc->setNextPC(val); } 3102455SN/A 3117897Shestness@cs.utexas.edu uint64_t readUniq() { return xc->readUniq(); } 3129918Ssteve.reinhardt@amd.com void setUniq(uint64_t val) { xc->setUniq(val); } 3132683Sktlim@umich.edu 314726SN/A uint64_t readFpcr() { return xc->readFpcr(); } 315705SN/A void setFpcr(uint64_t val) { xc->setFpcr(val); } 3169920Syasuko.eckert@amd.com 3179920Syasuko.eckert@amd.com#ifdef FULL_SYSTEM 3189920Syasuko.eckert@amd.com uint64_t readIpr(int idx, Fault &fault) { return xc->readIpr(idx, fault); } 3199920Syasuko.eckert@amd.com Fault setIpr(int idx, uint64_t val) { return xc->setIpr(idx, val); } 3209920Syasuko.eckert@amd.com Fault hwrei() { return xc->hwrei(); } 3219920Syasuko.eckert@amd.com int readIntrFlag() { return xc->readIntrFlag(); } 3229920Syasuko.eckert@amd.com void setIntrFlag(int val) { xc->setIntrFlag(val); } 3233735Sstever@eecs.umich.edu bool inPalMode() { return xc->inPalMode(); } 324726SN/A void ev5_trap(Fault fault) { xc->ev5_trap(fault); } 3257897Shestness@cs.utexas.edu bool simPalCheck(int palFunc) { return xc->simPalCheck(palFunc); } 3262683Sktlim@umich.edu#else 327726SN/A void syscall() { xc->syscall(); } 328705SN/A#endif 3293735Sstever@eecs.umich.edu 330726SN/A bool misspeculating() { return xc->misspeculating(); } 3317897Shestness@cs.utexas.edu ExecContext *xcBase() { return xc; } 3329918Ssteve.reinhardt@amd.com}; 3332683Sktlim@umich.edu 334726SN/A#endif // __CPU_SIMPLE_CPU_SIMPLE_CPU_HH__ 335726SN/A