base.hh revision 6658
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" 396658Snate@binkert.org#include "config/the_isa.hh" 401717SN/A#include "cpu/base.hh" 412683Sktlim@umich.edu#include "cpu/simple_thread.hh" 421354SN/A#include "cpu/pc_event.hh" 431354SN/A#include "cpu/static_inst.hh" 442387SN/A#include "mem/packet.hh" 452387SN/A#include "mem/port.hh" 462387SN/A#include "mem/request.hh" 4756SN/A#include "sim/eventq.hh" 485348Ssaidi@eecs.umich.edu#include "sim/system.hh" 492SN/A 502SN/A// forward declarations 511858SN/A#if FULL_SYSTEM 522SN/Aclass Processor; 533453Sgblack@eecs.umich.edunamespace TheISA 543453Sgblack@eecs.umich.edu{ 553453Sgblack@eecs.umich.edu class ITB; 563453Sgblack@eecs.umich.edu class DTB; 573453Sgblack@eecs.umich.edu} 582462SN/Aclass MemObject; 592SN/A 60715SN/A#else 61715SN/A 62715SN/Aclass Process; 63715SN/A 642SN/A#endif // FULL_SYSTEM 652SN/A 663960Sgblack@eecs.umich.educlass RemoteGDB; 673960Sgblack@eecs.umich.educlass GDBListener; 683960Sgblack@eecs.umich.edu 694182Sgblack@eecs.umich.edunamespace TheISA 704182Sgblack@eecs.umich.edu{ 714182Sgblack@eecs.umich.edu class Predecoder; 724182Sgblack@eecs.umich.edu} 732680Sktlim@umich.educlass ThreadContext; 74237SN/Aclass Checkpoint; 752SN/A 762SN/Anamespace Trace { 772SN/A class InstRecord; 782SN/A} 792SN/A 805529Snate@binkert.orgclass BaseSimpleCPUParams; 815529Snate@binkert.org 822420SN/A 832623SN/Aclass BaseSimpleCPU : public BaseCPU 842SN/A{ 852107SN/A protected: 862159SN/A typedef TheISA::MiscReg MiscReg; 872455SN/A typedef TheISA::FloatReg FloatReg; 882455SN/A typedef TheISA::FloatRegBits FloatRegBits; 892386SN/A 902623SN/A protected: 912SN/A Trace::InstRecord *traceData; 921371SN/A 935348Ssaidi@eecs.umich.edu inline void checkPcEventQueue() { 945348Ssaidi@eecs.umich.edu Addr oldpc; 955348Ssaidi@eecs.umich.edu do { 965348Ssaidi@eecs.umich.edu oldpc = thread->readPC(); 975348Ssaidi@eecs.umich.edu system->pcEventQueue.service(tc); 985348Ssaidi@eecs.umich.edu } while (oldpc != thread->readPC()); 995348Ssaidi@eecs.umich.edu } 1005348Ssaidi@eecs.umich.edu 1012SN/A public: 1025807Snate@binkert.org void wakeup(); 1032SN/A 1042SN/A void zero_fill_64(Addr addr) { 1052SN/A static int warned = 0; 1062SN/A if (!warned) { 1072SN/A warn ("WH64 is not implemented"); 1082SN/A warned = 1; 1092SN/A } 1102SN/A }; 1112SN/A 1121400SN/A public: 1135529Snate@binkert.org BaseSimpleCPU(BaseSimpleCPUParams *params); 1142623SN/A virtual ~BaseSimpleCPU(); 1152SN/A 1161400SN/A public: 1172683Sktlim@umich.edu /** SimpleThread object, provides all the architectural state. */ 1182683Sktlim@umich.edu SimpleThread *thread; 1192190SN/A 1202683Sktlim@umich.edu /** ThreadContext object, provides an interface for external 1212683Sktlim@umich.edu * objects to modify this thread's state. 1222683Sktlim@umich.edu */ 1232680Sktlim@umich.edu ThreadContext *tc; 1245169Ssaidi@eecs.umich.edu protected: 1255169Ssaidi@eecs.umich.edu 1265496Ssaidi@eecs.umich.edu enum Status { 1275496Ssaidi@eecs.umich.edu Idle, 1285496Ssaidi@eecs.umich.edu Running, 1295894Sgblack@eecs.umich.edu ITBWaitResponse, 1305496Ssaidi@eecs.umich.edu IcacheRetry, 1315496Ssaidi@eecs.umich.edu IcacheWaitResponse, 1325496Ssaidi@eecs.umich.edu IcacheWaitSwitch, 1335894Sgblack@eecs.umich.edu DTBWaitResponse, 1345496Ssaidi@eecs.umich.edu DcacheRetry, 1355496Ssaidi@eecs.umich.edu DcacheWaitResponse, 1365496Ssaidi@eecs.umich.edu DcacheWaitSwitch, 1375496Ssaidi@eecs.umich.edu SwitchedOut 1385496Ssaidi@eecs.umich.edu }; 1395496Ssaidi@eecs.umich.edu 1405496Ssaidi@eecs.umich.edu Status _status; 1415496Ssaidi@eecs.umich.edu 1425169Ssaidi@eecs.umich.edu public: 1432SN/A 1441858SN/A#if FULL_SYSTEM 1452SN/A Addr dbg_vtophys(Addr addr); 1462SN/A 1472SN/A bool interval_stats; 1482SN/A#endif 1492SN/A 1502SN/A // current instruction 1514181Sgblack@eecs.umich.edu TheISA::MachInst inst; 1524181Sgblack@eecs.umich.edu 1534182Sgblack@eecs.umich.edu // The predecoder 1544182Sgblack@eecs.umich.edu TheISA::Predecoder predecoder; 1552SN/A 1562107SN/A StaticInstPtr curStaticInst; 1573276Sgblack@eecs.umich.edu StaticInstPtr curMacroStaticInst; 1581469SN/A 1594377Sgblack@eecs.umich.edu //This is the offset from the current pc that fetch should be performed at 1604377Sgblack@eecs.umich.edu Addr fetchOffset; 1614377Sgblack@eecs.umich.edu //This flag says to stay at the current pc. This is useful for 1624377Sgblack@eecs.umich.edu //instructions which go beyond MachInst boundaries. 1634377Sgblack@eecs.umich.edu bool stayAtPC; 1644377Sgblack@eecs.umich.edu 1652623SN/A void checkForInterrupts(); 1665894Sgblack@eecs.umich.edu void setupFetchRequest(Request *req); 1672623SN/A void preExecute(); 1682623SN/A void postExecute(); 1692623SN/A void advancePC(Fault fault); 170180SN/A 171393SN/A virtual void deallocateContext(int thread_num); 172393SN/A virtual void haltContext(int thread_num); 1732SN/A 1742SN/A // statistics 175334SN/A virtual void regStats(); 176334SN/A virtual void resetStats(); 1772SN/A 1782SN/A // number of simulated instructions 1792SN/A Counter numInst; 180334SN/A Counter startNumInst; 1815999Snate@binkert.org Stats::Scalar numInsts; 182707SN/A 1834998Sgblack@eecs.umich.edu void countInst() 1844998Sgblack@eecs.umich.edu { 1854998Sgblack@eecs.umich.edu numInst++; 1864998Sgblack@eecs.umich.edu numInsts++; 1874998Sgblack@eecs.umich.edu 1884998Sgblack@eecs.umich.edu thread->funcExeInst++; 1894998Sgblack@eecs.umich.edu } 1904998Sgblack@eecs.umich.edu 191707SN/A virtual Counter totalInstructions() const 192707SN/A { 193707SN/A return numInst - startNumInst; 194707SN/A } 1952SN/A 1964564Sgblack@eecs.umich.edu // Mask to align PCs to MachInst sized boundaries 1974564Sgblack@eecs.umich.edu static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1); 1984564Sgblack@eecs.umich.edu 1992SN/A // number of simulated memory references 2005999Snate@binkert.org Stats::Scalar numMemRefs; 2012SN/A 202124SN/A // number of simulated loads 203124SN/A Counter numLoad; 204334SN/A Counter startNumLoad; 205124SN/A 2062SN/A // number of idle cycles 2075999Snate@binkert.org Stats::Average notIdleFraction; 208729SN/A Stats::Formula idleFraction; 2092SN/A 2102390SN/A // number of cycles stalled for I-cache responses 2115999Snate@binkert.org Stats::Scalar icacheStallCycles; 2122SN/A Counter lastIcacheStall; 2132SN/A 2142390SN/A // number of cycles stalled for I-cache retries 2155999Snate@binkert.org Stats::Scalar icacheRetryCycles; 2162390SN/A Counter lastIcacheRetry; 2172390SN/A 2182390SN/A // number of cycles stalled for D-cache responses 2195999Snate@binkert.org Stats::Scalar dcacheStallCycles; 2202SN/A Counter lastDcacheStall; 2212SN/A 2222390SN/A // number of cycles stalled for D-cache retries 2235999Snate@binkert.org Stats::Scalar dcacheRetryCycles; 2242390SN/A Counter lastDcacheRetry; 2252390SN/A 226217SN/A virtual void serialize(std::ostream &os); 227237SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 2282SN/A 2291371SN/A // These functions are only used in CPU models that split 2301371SN/A // effective address computation from the actual memory access. 2312623SN/A void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); } 2325543Ssaidi@eecs.umich.edu Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n"); 2333918Ssaidi@eecs.umich.edu M5_DUMMY_RETURN} 2341371SN/A 235581SN/A void prefetch(Addr addr, unsigned flags) 2362SN/A { 2372SN/A // need to do this... 2382SN/A } 2392SN/A 240753SN/A void writeHint(Addr addr, int size, unsigned flags) 2412SN/A { 2422SN/A // need to do this... 2432SN/A } 244594SN/A 2454661Sksewell@umich.edu 246595SN/A Fault copySrcTranslate(Addr src); 247594SN/A 248595SN/A Fault copy(Addr dest); 249705SN/A 250726SN/A // The register accessor methods provide the index of the 251726SN/A // instruction's operand (e.g., 0 or 1), not the architectural 252726SN/A // register index, to simplify the implementation of register 253726SN/A // renaming. We find the architectural register index by indexing 254726SN/A // into the instruction's own operand index table. Note that a 255726SN/A // raw pointer to the StaticInst is provided instead of a 256726SN/A // ref-counted StaticInstPtr to redice overhead. This is fine as 257726SN/A // long as these methods don't copy the pointer into any long-term 258726SN/A // storage (which is pretty hard to imagine they would have reason 259726SN/A // to do). 260705SN/A 2613735Sstever@eecs.umich.edu uint64_t readIntRegOperand(const StaticInst *si, int idx) 262726SN/A { 2632683Sktlim@umich.edu return thread->readIntReg(si->srcRegIdx(idx)); 264726SN/A } 265705SN/A 2663735Sstever@eecs.umich.edu FloatReg readFloatRegOperand(const StaticInst *si, int idx) 267726SN/A { 268726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2692683Sktlim@umich.edu return thread->readFloatReg(reg_idx); 270726SN/A } 271705SN/A 2723735Sstever@eecs.umich.edu FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) 2732455SN/A { 2742455SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2752683Sktlim@umich.edu return thread->readFloatRegBits(reg_idx); 276726SN/A } 277705SN/A 2783735Sstever@eecs.umich.edu void setIntRegOperand(const StaticInst *si, int idx, uint64_t val) 279726SN/A { 2802683Sktlim@umich.edu thread->setIntReg(si->destRegIdx(idx), val); 281726SN/A } 282705SN/A 2833735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) 284726SN/A { 285726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2862683Sktlim@umich.edu thread->setFloatReg(reg_idx, val); 287726SN/A } 288726SN/A 2893735Sstever@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 2903735Sstever@eecs.umich.edu FloatRegBits val) 2912455SN/A { 2922455SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2932683Sktlim@umich.edu thread->setFloatRegBits(reg_idx, val); 294726SN/A } 295705SN/A 2962683Sktlim@umich.edu uint64_t readPC() { return thread->readPC(); } 2974950Sgblack@eecs.umich.edu uint64_t readMicroPC() { return thread->readMicroPC(); } 2982683Sktlim@umich.edu uint64_t readNextPC() { return thread->readNextPC(); } 2994950Sgblack@eecs.umich.edu uint64_t readNextMicroPC() { return thread->readNextMicroPC(); } 3002683Sktlim@umich.edu uint64_t readNextNPC() { return thread->readNextNPC(); } 3012447SN/A 3022683Sktlim@umich.edu void setPC(uint64_t val) { thread->setPC(val); } 3034950Sgblack@eecs.umich.edu void setMicroPC(uint64_t val) { thread->setMicroPC(val); } 3042683Sktlim@umich.edu void setNextPC(uint64_t val) { thread->setNextPC(val); } 3054950Sgblack@eecs.umich.edu void setNextMicroPC(uint64_t val) { thread->setNextMicroPC(val); } 3062683Sktlim@umich.edu void setNextNPC(uint64_t val) { thread->setNextNPC(val); } 307705SN/A 3084172Ssaidi@eecs.umich.edu MiscReg readMiscRegNoEffect(int misc_reg) 3094172Ssaidi@eecs.umich.edu { 3104172Ssaidi@eecs.umich.edu return thread->readMiscRegNoEffect(misc_reg); 3114172Ssaidi@eecs.umich.edu } 3124172Ssaidi@eecs.umich.edu 3132159SN/A MiscReg readMiscReg(int misc_reg) 3142159SN/A { 3152683Sktlim@umich.edu return thread->readMiscReg(misc_reg); 3162159SN/A } 317705SN/A 3184172Ssaidi@eecs.umich.edu void setMiscRegNoEffect(int misc_reg, const MiscReg &val) 3192159SN/A { 3204172Ssaidi@eecs.umich.edu return thread->setMiscRegNoEffect(misc_reg, val); 3212159SN/A } 3222159SN/A 3233468Sgblack@eecs.umich.edu void setMiscReg(int misc_reg, const MiscReg &val) 3242159SN/A { 3252683Sktlim@umich.edu return thread->setMiscReg(misc_reg, val); 3262159SN/A } 3272159SN/A 3284185Ssaidi@eecs.umich.edu MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx) 3292159SN/A { 3304172Ssaidi@eecs.umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3314172Ssaidi@eecs.umich.edu return thread->readMiscRegNoEffect(reg_idx); 3322159SN/A } 333705SN/A 3344185Ssaidi@eecs.umich.edu MiscReg readMiscRegOperand(const StaticInst *si, int idx) 3353792Sgblack@eecs.umich.edu { 3363792Sgblack@eecs.umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3373792Sgblack@eecs.umich.edu return thread->readMiscReg(reg_idx); 3383792Sgblack@eecs.umich.edu } 3393792Sgblack@eecs.umich.edu 3404185Ssaidi@eecs.umich.edu void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val) 3413792Sgblack@eecs.umich.edu { 3423792Sgblack@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3434172Ssaidi@eecs.umich.edu return thread->setMiscRegNoEffect(reg_idx, val); 3443792Sgblack@eecs.umich.edu } 3453792Sgblack@eecs.umich.edu 3464185Ssaidi@eecs.umich.edu void setMiscRegOperand( 3473792Sgblack@eecs.umich.edu const StaticInst *si, int idx, const MiscReg &val) 3483792Sgblack@eecs.umich.edu { 3493792Sgblack@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3504172Ssaidi@eecs.umich.edu return thread->setMiscReg(reg_idx, val); 3513792Sgblack@eecs.umich.edu } 3523792Sgblack@eecs.umich.edu 3535358Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 3545358Sgblack@eecs.umich.edu { 3555358Sgblack@eecs.umich.edu thread->demapPage(vaddr, asn); 3565358Sgblack@eecs.umich.edu } 3575358Sgblack@eecs.umich.edu 3585358Sgblack@eecs.umich.edu void demapInstPage(Addr vaddr, uint64_t asn) 3595358Sgblack@eecs.umich.edu { 3605358Sgblack@eecs.umich.edu thread->demapInstPage(vaddr, asn); 3615358Sgblack@eecs.umich.edu } 3625358Sgblack@eecs.umich.edu 3635358Sgblack@eecs.umich.edu void demapDataPage(Addr vaddr, uint64_t asn) 3645358Sgblack@eecs.umich.edu { 3655358Sgblack@eecs.umich.edu thread->demapDataPage(vaddr, asn); 3665358Sgblack@eecs.umich.edu } 3675358Sgblack@eecs.umich.edu 3684027Sstever@eecs.umich.edu unsigned readStCondFailures() { 3694027Sstever@eecs.umich.edu return thread->readStCondFailures(); 3704027Sstever@eecs.umich.edu } 3714027Sstever@eecs.umich.edu 3724027Sstever@eecs.umich.edu void setStCondFailures(unsigned sc_failures) { 3734027Sstever@eecs.umich.edu thread->setStCondFailures(sc_failures); 3744027Sstever@eecs.umich.edu } 3754027Sstever@eecs.umich.edu 3766221Snate@binkert.org MiscReg readRegOtherThread(int regIdx, ThreadID tid = InvalidThreadID) 3774661Sksewell@umich.edu { 3784661Sksewell@umich.edu panic("Simple CPU models do not support multithreaded " 3794661Sksewell@umich.edu "register access.\n"); 3804661Sksewell@umich.edu } 3814661Sksewell@umich.edu 3826221Snate@binkert.org void setRegOtherThread(int regIdx, const MiscReg &val, 3836221Snate@binkert.org ThreadID tid = InvalidThreadID) 3844661Sksewell@umich.edu { 3854661Sksewell@umich.edu panic("Simple CPU models do not support multithreaded " 3864661Sksewell@umich.edu "register access.\n"); 3874661Sksewell@umich.edu } 3884661Sksewell@umich.edu 3895250Sksewell@umich.edu //Fault CacheOp(uint8_t Op, Addr EA); 3905222Sksewell@umich.edu 3911858SN/A#if FULL_SYSTEM 3925702Ssaidi@eecs.umich.edu Fault hwrei() { return thread->hwrei(); } 3932680Sktlim@umich.edu void ev5_trap(Fault fault) { fault->invoke(tc); } 3945702Ssaidi@eecs.umich.edu bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); } 395705SN/A#else 3962683Sktlim@umich.edu void syscall(int64_t callnum) { thread->syscall(callnum); } 397705SN/A#endif 398705SN/A 3992683Sktlim@umich.edu bool misspeculating() { return thread->misspeculating(); } 4002680Sktlim@umich.edu ThreadContext *tcBase() { return tc; } 4012SN/A}; 4022SN/A 4032623SN/A#endif // __CPU_SIMPLE_BASE_HH__ 404