base.hh revision 5496
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/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. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Dave Greene 302665Ssaidi@eecs.umich.edu * Nathan Binkert 312SN/A */ 322SN/A 332623SN/A#ifndef __CPU_SIMPLE_BASE_HH__ 342623SN/A#define __CPU_SIMPLE_BASE_HH__ 352SN/A 364182Sgblack@eecs.umich.edu#include "arch/predecoder.hh" 371354SN/A#include "base/statistics.hh" 381858SN/A#include "config/full_system.hh" 391717SN/A#include "cpu/base.hh" 402683Sktlim@umich.edu#include "cpu/simple_thread.hh" 411354SN/A#include "cpu/pc_event.hh" 421354SN/A#include "cpu/static_inst.hh" 432387SN/A#include "mem/packet.hh" 442387SN/A#include "mem/port.hh" 452387SN/A#include "mem/request.hh" 4656SN/A#include "sim/eventq.hh" 475348Ssaidi@eecs.umich.edu#include "sim/system.hh" 482SN/A 492SN/A// forward declarations 501858SN/A#if FULL_SYSTEM 512SN/Aclass Processor; 523453Sgblack@eecs.umich.edunamespace TheISA 533453Sgblack@eecs.umich.edu{ 543453Sgblack@eecs.umich.edu class ITB; 553453Sgblack@eecs.umich.edu class DTB; 563453Sgblack@eecs.umich.edu} 572462SN/Aclass MemObject; 582SN/A 59715SN/A#else 60715SN/A 61715SN/Aclass Process; 62715SN/A 632SN/A#endif // FULL_SYSTEM 642SN/A 653960Sgblack@eecs.umich.educlass RemoteGDB; 663960Sgblack@eecs.umich.educlass GDBListener; 673960Sgblack@eecs.umich.edu 684182Sgblack@eecs.umich.edunamespace TheISA 694182Sgblack@eecs.umich.edu{ 704182Sgblack@eecs.umich.edu class Predecoder; 714182Sgblack@eecs.umich.edu} 722680Sktlim@umich.educlass ThreadContext; 73237SN/Aclass Checkpoint; 742SN/A 752SN/Anamespace Trace { 762SN/A class InstRecord; 772SN/A} 782SN/A 792420SN/A 802623SN/Aclass BaseSimpleCPU : public BaseCPU 812SN/A{ 822107SN/A protected: 832159SN/A typedef TheISA::MiscReg MiscReg; 842455SN/A typedef TheISA::FloatReg FloatReg; 852455SN/A typedef TheISA::FloatRegBits FloatRegBits; 862386SN/A 872623SN/A protected: 882SN/A Trace::InstRecord *traceData; 891371SN/A 905348Ssaidi@eecs.umich.edu inline void checkPcEventQueue() { 915348Ssaidi@eecs.umich.edu Addr oldpc; 925348Ssaidi@eecs.umich.edu do { 935348Ssaidi@eecs.umich.edu oldpc = thread->readPC(); 945348Ssaidi@eecs.umich.edu system->pcEventQueue.service(tc); 955348Ssaidi@eecs.umich.edu } while (oldpc != thread->readPC()); 965348Ssaidi@eecs.umich.edu } 975348Ssaidi@eecs.umich.edu 982SN/A public: 992SN/A void post_interrupt(int int_num, int index); 1002SN/A 1012SN/A void zero_fill_64(Addr addr) { 1022SN/A static int warned = 0; 1032SN/A if (!warned) { 1042SN/A warn ("WH64 is not implemented"); 1052SN/A warned = 1; 1062SN/A } 1072SN/A }; 1082SN/A 1091400SN/A public: 1101400SN/A struct Params : public BaseCPU::Params 1111400SN/A { 1123453Sgblack@eecs.umich.edu TheISA::ITB *itb; 1133453Sgblack@eecs.umich.edu TheISA::DTB *dtb; 1144997Sgblack@eecs.umich.edu#if !FULL_SYSTEM 1151400SN/A Process *process; 1162SN/A#endif 1171400SN/A }; 1182623SN/A BaseSimpleCPU(Params *params); 1192623SN/A virtual ~BaseSimpleCPU(); 1202SN/A 1211400SN/A public: 1222683Sktlim@umich.edu /** SimpleThread object, provides all the architectural state. */ 1232683Sktlim@umich.edu SimpleThread *thread; 1242190SN/A 1252683Sktlim@umich.edu /** ThreadContext object, provides an interface for external 1262683Sktlim@umich.edu * objects to modify this thread's state. 1272683Sktlim@umich.edu */ 1282680Sktlim@umich.edu ThreadContext *tc; 1295169Ssaidi@eecs.umich.edu protected: 1305169Ssaidi@eecs.umich.edu int cpuId; 1315169Ssaidi@eecs.umich.edu 1325496Ssaidi@eecs.umich.edu enum Status { 1335496Ssaidi@eecs.umich.edu Idle, 1345496Ssaidi@eecs.umich.edu Running, 1355496Ssaidi@eecs.umich.edu IcacheRetry, 1365496Ssaidi@eecs.umich.edu IcacheWaitResponse, 1375496Ssaidi@eecs.umich.edu IcacheWaitSwitch, 1385496Ssaidi@eecs.umich.edu DcacheRetry, 1395496Ssaidi@eecs.umich.edu DcacheWaitResponse, 1405496Ssaidi@eecs.umich.edu DcacheWaitSwitch, 1415496Ssaidi@eecs.umich.edu SwitchedOut 1425496Ssaidi@eecs.umich.edu }; 1435496Ssaidi@eecs.umich.edu 1445496Ssaidi@eecs.umich.edu Status _status; 1455496Ssaidi@eecs.umich.edu 1465169Ssaidi@eecs.umich.edu public: 1472SN/A 1481858SN/A#if FULL_SYSTEM 1492SN/A Addr dbg_vtophys(Addr addr); 1502SN/A 1512SN/A bool interval_stats; 1522SN/A#endif 1532SN/A 1542SN/A // current instruction 1554181Sgblack@eecs.umich.edu TheISA::MachInst inst; 1564181Sgblack@eecs.umich.edu 1574182Sgblack@eecs.umich.edu // The predecoder 1584182Sgblack@eecs.umich.edu TheISA::Predecoder predecoder; 1592SN/A 1602107SN/A StaticInstPtr curStaticInst; 1613276Sgblack@eecs.umich.edu StaticInstPtr curMacroStaticInst; 1621469SN/A 1634377Sgblack@eecs.umich.edu //This is the offset from the current pc that fetch should be performed at 1644377Sgblack@eecs.umich.edu Addr fetchOffset; 1654377Sgblack@eecs.umich.edu //This flag says to stay at the current pc. This is useful for 1664377Sgblack@eecs.umich.edu //instructions which go beyond MachInst boundaries. 1674377Sgblack@eecs.umich.edu bool stayAtPC; 1684377Sgblack@eecs.umich.edu 1692623SN/A void checkForInterrupts(); 1702662Sstever@eecs.umich.edu Fault setupFetchRequest(Request *req); 1712623SN/A void preExecute(); 1722623SN/A void postExecute(); 1732623SN/A void advancePC(Fault fault); 174180SN/A 175393SN/A virtual void deallocateContext(int thread_num); 176393SN/A virtual void haltContext(int thread_num); 1772SN/A 1782SN/A // statistics 179334SN/A virtual void regStats(); 180334SN/A virtual void resetStats(); 1812SN/A 1822SN/A // number of simulated instructions 1832SN/A Counter numInst; 184334SN/A Counter startNumInst; 185729SN/A Stats::Scalar<> numInsts; 186707SN/A 1874998Sgblack@eecs.umich.edu void countInst() 1884998Sgblack@eecs.umich.edu { 1894998Sgblack@eecs.umich.edu numInst++; 1904998Sgblack@eecs.umich.edu numInsts++; 1914998Sgblack@eecs.umich.edu 1924998Sgblack@eecs.umich.edu thread->funcExeInst++; 1934998Sgblack@eecs.umich.edu } 1944998Sgblack@eecs.umich.edu 195707SN/A virtual Counter totalInstructions() const 196707SN/A { 197707SN/A return numInst - startNumInst; 198707SN/A } 1992SN/A 2004564Sgblack@eecs.umich.edu // Mask to align PCs to MachInst sized boundaries 2014564Sgblack@eecs.umich.edu static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1); 2024564Sgblack@eecs.umich.edu 2032SN/A // number of simulated memory references 204729SN/A Stats::Scalar<> numMemRefs; 2052SN/A 206124SN/A // number of simulated loads 207124SN/A Counter numLoad; 208334SN/A Counter startNumLoad; 209124SN/A 2102SN/A // number of idle cycles 211729SN/A Stats::Average<> notIdleFraction; 212729SN/A Stats::Formula idleFraction; 2132SN/A 2142390SN/A // number of cycles stalled for I-cache responses 215729SN/A Stats::Scalar<> icacheStallCycles; 2162SN/A Counter lastIcacheStall; 2172SN/A 2182390SN/A // number of cycles stalled for I-cache retries 2192390SN/A Stats::Scalar<> icacheRetryCycles; 2202390SN/A Counter lastIcacheRetry; 2212390SN/A 2222390SN/A // number of cycles stalled for D-cache responses 223729SN/A Stats::Scalar<> dcacheStallCycles; 2242SN/A Counter lastDcacheStall; 2252SN/A 2262390SN/A // number of cycles stalled for D-cache retries 2272390SN/A Stats::Scalar<> dcacheRetryCycles; 2282390SN/A Counter lastDcacheRetry; 2292390SN/A 230217SN/A virtual void serialize(std::ostream &os); 231237SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 2322SN/A 2331371SN/A // These functions are only used in CPU models that split 2341371SN/A // effective address computation from the actual memory access. 2352623SN/A void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); } 2363918Ssaidi@eecs.umich.edu Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n"); 2373918Ssaidi@eecs.umich.edu M5_DUMMY_RETURN} 2381371SN/A 239581SN/A void prefetch(Addr addr, unsigned flags) 2402SN/A { 2412SN/A // need to do this... 2422SN/A } 2432SN/A 244753SN/A void writeHint(Addr addr, int size, unsigned flags) 2452SN/A { 2462SN/A // need to do this... 2472SN/A } 248594SN/A 2494661Sksewell@umich.edu 250595SN/A Fault copySrcTranslate(Addr src); 251594SN/A 252595SN/A Fault copy(Addr dest); 253705SN/A 254726SN/A // The register accessor methods provide the index of the 255726SN/A // instruction's operand (e.g., 0 or 1), not the architectural 256726SN/A // register index, to simplify the implementation of register 257726SN/A // renaming. We find the architectural register index by indexing 258726SN/A // into the instruction's own operand index table. Note that a 259726SN/A // raw pointer to the StaticInst is provided instead of a 260726SN/A // ref-counted StaticInstPtr to redice overhead. This is fine as 261726SN/A // long as these methods don't copy the pointer into any long-term 262726SN/A // storage (which is pretty hard to imagine they would have reason 263726SN/A // to do). 264705SN/A 2653735Sstever@eecs.umich.edu uint64_t readIntRegOperand(const StaticInst *si, int idx) 266726SN/A { 2672683Sktlim@umich.edu return thread->readIntReg(si->srcRegIdx(idx)); 268726SN/A } 269705SN/A 2703735Sstever@eecs.umich.edu FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width) 271726SN/A { 272726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2732683Sktlim@umich.edu return thread->readFloatReg(reg_idx, width); 274726SN/A } 275705SN/A 2763735Sstever@eecs.umich.edu FloatReg readFloatRegOperand(const StaticInst *si, int idx) 277726SN/A { 278726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2792683Sktlim@umich.edu return thread->readFloatReg(reg_idx); 280726SN/A } 281705SN/A 2823735Sstever@eecs.umich.edu FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx, 2833735Sstever@eecs.umich.edu int width) 284726SN/A { 285726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2862683Sktlim@umich.edu return thread->readFloatRegBits(reg_idx, width); 2872455SN/A } 2882455SN/A 2893735Sstever@eecs.umich.edu FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) 2902455SN/A { 2912455SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2922683Sktlim@umich.edu return thread->readFloatRegBits(reg_idx); 293726SN/A } 294705SN/A 2953735Sstever@eecs.umich.edu void setIntRegOperand(const StaticInst *si, int idx, uint64_t val) 296726SN/A { 2972683Sktlim@umich.edu thread->setIntReg(si->destRegIdx(idx), val); 298726SN/A } 299705SN/A 3003735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val, 3013735Sstever@eecs.umich.edu int width) 302726SN/A { 303726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3042683Sktlim@umich.edu thread->setFloatReg(reg_idx, val, width); 305726SN/A } 306705SN/A 3073735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) 308726SN/A { 309726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3102683Sktlim@umich.edu thread->setFloatReg(reg_idx, val); 311726SN/A } 312726SN/A 3133735Sstever@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 3143735Sstever@eecs.umich.edu FloatRegBits val, int width) 315726SN/A { 316726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3172683Sktlim@umich.edu thread->setFloatRegBits(reg_idx, val, width); 3182455SN/A } 3192455SN/A 3203735Sstever@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 3213735Sstever@eecs.umich.edu FloatRegBits val) 3222455SN/A { 3232455SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3242683Sktlim@umich.edu thread->setFloatRegBits(reg_idx, val); 325726SN/A } 326705SN/A 3272683Sktlim@umich.edu uint64_t readPC() { return thread->readPC(); } 3284950Sgblack@eecs.umich.edu uint64_t readMicroPC() { return thread->readMicroPC(); } 3292683Sktlim@umich.edu uint64_t readNextPC() { return thread->readNextPC(); } 3304950Sgblack@eecs.umich.edu uint64_t readNextMicroPC() { return thread->readNextMicroPC(); } 3312683Sktlim@umich.edu uint64_t readNextNPC() { return thread->readNextNPC(); } 3322447SN/A 3332683Sktlim@umich.edu void setPC(uint64_t val) { thread->setPC(val); } 3344950Sgblack@eecs.umich.edu void setMicroPC(uint64_t val) { thread->setMicroPC(val); } 3352683Sktlim@umich.edu void setNextPC(uint64_t val) { thread->setNextPC(val); } 3364950Sgblack@eecs.umich.edu void setNextMicroPC(uint64_t val) { thread->setNextMicroPC(val); } 3372683Sktlim@umich.edu void setNextNPC(uint64_t val) { thread->setNextNPC(val); } 338705SN/A 3394172Ssaidi@eecs.umich.edu MiscReg readMiscRegNoEffect(int misc_reg) 3404172Ssaidi@eecs.umich.edu { 3414172Ssaidi@eecs.umich.edu return thread->readMiscRegNoEffect(misc_reg); 3424172Ssaidi@eecs.umich.edu } 3434172Ssaidi@eecs.umich.edu 3442159SN/A MiscReg readMiscReg(int misc_reg) 3452159SN/A { 3462683Sktlim@umich.edu return thread->readMiscReg(misc_reg); 3472159SN/A } 348705SN/A 3494172Ssaidi@eecs.umich.edu void setMiscRegNoEffect(int misc_reg, const MiscReg &val) 3502159SN/A { 3514172Ssaidi@eecs.umich.edu return thread->setMiscRegNoEffect(misc_reg, val); 3522159SN/A } 3532159SN/A 3543468Sgblack@eecs.umich.edu void setMiscReg(int misc_reg, const MiscReg &val) 3552159SN/A { 3562683Sktlim@umich.edu return thread->setMiscReg(misc_reg, val); 3572159SN/A } 3582159SN/A 3594185Ssaidi@eecs.umich.edu MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx) 3602159SN/A { 3614172Ssaidi@eecs.umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3624172Ssaidi@eecs.umich.edu return thread->readMiscRegNoEffect(reg_idx); 3632159SN/A } 364705SN/A 3654185Ssaidi@eecs.umich.edu MiscReg readMiscRegOperand(const StaticInst *si, int idx) 3663792Sgblack@eecs.umich.edu { 3673792Sgblack@eecs.umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3683792Sgblack@eecs.umich.edu return thread->readMiscReg(reg_idx); 3693792Sgblack@eecs.umich.edu } 3703792Sgblack@eecs.umich.edu 3714185Ssaidi@eecs.umich.edu void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val) 3723792Sgblack@eecs.umich.edu { 3733792Sgblack@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3744172Ssaidi@eecs.umich.edu return thread->setMiscRegNoEffect(reg_idx, val); 3753792Sgblack@eecs.umich.edu } 3763792Sgblack@eecs.umich.edu 3774185Ssaidi@eecs.umich.edu void setMiscRegOperand( 3783792Sgblack@eecs.umich.edu const StaticInst *si, int idx, const MiscReg &val) 3793792Sgblack@eecs.umich.edu { 3803792Sgblack@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3814172Ssaidi@eecs.umich.edu return thread->setMiscReg(reg_idx, val); 3823792Sgblack@eecs.umich.edu } 3833792Sgblack@eecs.umich.edu 3845358Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 3855358Sgblack@eecs.umich.edu { 3865358Sgblack@eecs.umich.edu thread->demapPage(vaddr, asn); 3875358Sgblack@eecs.umich.edu } 3885358Sgblack@eecs.umich.edu 3895358Sgblack@eecs.umich.edu void demapInstPage(Addr vaddr, uint64_t asn) 3905358Sgblack@eecs.umich.edu { 3915358Sgblack@eecs.umich.edu thread->demapInstPage(vaddr, asn); 3925358Sgblack@eecs.umich.edu } 3935358Sgblack@eecs.umich.edu 3945358Sgblack@eecs.umich.edu void demapDataPage(Addr vaddr, uint64_t asn) 3955358Sgblack@eecs.umich.edu { 3965358Sgblack@eecs.umich.edu thread->demapDataPage(vaddr, asn); 3975358Sgblack@eecs.umich.edu } 3985358Sgblack@eecs.umich.edu 3994027Sstever@eecs.umich.edu unsigned readStCondFailures() { 4004027Sstever@eecs.umich.edu return thread->readStCondFailures(); 4014027Sstever@eecs.umich.edu } 4024027Sstever@eecs.umich.edu 4034027Sstever@eecs.umich.edu void setStCondFailures(unsigned sc_failures) { 4044027Sstever@eecs.umich.edu thread->setStCondFailures(sc_failures); 4054027Sstever@eecs.umich.edu } 4064027Sstever@eecs.umich.edu 4074661Sksewell@umich.edu MiscReg readRegOtherThread(int regIdx, int tid = -1) 4084661Sksewell@umich.edu { 4094661Sksewell@umich.edu panic("Simple CPU models do not support multithreaded " 4104661Sksewell@umich.edu "register access.\n"); 4114661Sksewell@umich.edu } 4124661Sksewell@umich.edu 4134661Sksewell@umich.edu void setRegOtherThread(int regIdx, const MiscReg &val, int tid = -1) 4144661Sksewell@umich.edu { 4154661Sksewell@umich.edu panic("Simple CPU models do not support multithreaded " 4164661Sksewell@umich.edu "register access.\n"); 4174661Sksewell@umich.edu } 4184661Sksewell@umich.edu 4195250Sksewell@umich.edu //Fault CacheOp(uint8_t Op, Addr EA); 4205222Sksewell@umich.edu 4211858SN/A#if FULL_SYSTEM 4222683Sktlim@umich.edu Fault hwrei() { return thread->hwrei(); } 4232680Sktlim@umich.edu void ev5_trap(Fault fault) { fault->invoke(tc); } 4242683Sktlim@umich.edu bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); } 425705SN/A#else 4262683Sktlim@umich.edu void syscall(int64_t callnum) { thread->syscall(callnum); } 427705SN/A#endif 428705SN/A 4292683Sktlim@umich.edu bool misspeculating() { return thread->misspeculating(); } 4302680Sktlim@umich.edu ThreadContext *tcBase() { return tc; } 4312SN/A}; 4322SN/A 4332623SN/A#endif // __CPU_SIMPLE_BASE_HH__ 434