base.hh revision 7897
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 664182Sgblack@eecs.umich.edunamespace TheISA 674182Sgblack@eecs.umich.edu{ 684182Sgblack@eecs.umich.edu class Predecoder; 694182Sgblack@eecs.umich.edu} 702680Sktlim@umich.educlass ThreadContext; 71237SN/Aclass Checkpoint; 722SN/A 732SN/Anamespace Trace { 742SN/A class InstRecord; 752SN/A} 762SN/A 775529Snate@binkert.orgclass BaseSimpleCPUParams; 785529Snate@binkert.org 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() { 917720Sgblack@eecs.umich.edu Addr oldpc, pc = thread->instAddr(); 925348Ssaidi@eecs.umich.edu do { 937720Sgblack@eecs.umich.edu oldpc = pc; 945348Ssaidi@eecs.umich.edu system->pcEventQueue.service(tc); 957720Sgblack@eecs.umich.edu pc = thread->instAddr(); 967720Sgblack@eecs.umich.edu } while (oldpc != pc); 975348Ssaidi@eecs.umich.edu } 985348Ssaidi@eecs.umich.edu 992SN/A public: 1005807Snate@binkert.org void wakeup(); 1012SN/A 1022SN/A void zero_fill_64(Addr addr) { 1032SN/A static int warned = 0; 1042SN/A if (!warned) { 1052SN/A warn ("WH64 is not implemented"); 1062SN/A warned = 1; 1072SN/A } 1082SN/A }; 1092SN/A 1101400SN/A public: 1115529Snate@binkert.org BaseSimpleCPU(BaseSimpleCPUParams *params); 1122623SN/A virtual ~BaseSimpleCPU(); 1132SN/A 1141400SN/A public: 1152683Sktlim@umich.edu /** SimpleThread object, provides all the architectural state. */ 1162683Sktlim@umich.edu SimpleThread *thread; 1172190SN/A 1182683Sktlim@umich.edu /** ThreadContext object, provides an interface for external 1192683Sktlim@umich.edu * objects to modify this thread's state. 1202683Sktlim@umich.edu */ 1212680Sktlim@umich.edu ThreadContext *tc; 1225169Ssaidi@eecs.umich.edu protected: 1235169Ssaidi@eecs.umich.edu 1245496Ssaidi@eecs.umich.edu enum Status { 1255496Ssaidi@eecs.umich.edu Idle, 1265496Ssaidi@eecs.umich.edu Running, 1275894Sgblack@eecs.umich.edu ITBWaitResponse, 1285496Ssaidi@eecs.umich.edu IcacheRetry, 1295496Ssaidi@eecs.umich.edu IcacheWaitResponse, 1305496Ssaidi@eecs.umich.edu IcacheWaitSwitch, 1315894Sgblack@eecs.umich.edu DTBWaitResponse, 1325496Ssaidi@eecs.umich.edu DcacheRetry, 1335496Ssaidi@eecs.umich.edu DcacheWaitResponse, 1345496Ssaidi@eecs.umich.edu DcacheWaitSwitch, 1355496Ssaidi@eecs.umich.edu SwitchedOut 1365496Ssaidi@eecs.umich.edu }; 1375496Ssaidi@eecs.umich.edu 1385496Ssaidi@eecs.umich.edu Status _status; 1395496Ssaidi@eecs.umich.edu 1405169Ssaidi@eecs.umich.edu public: 1412SN/A 1421858SN/A#if FULL_SYSTEM 1432SN/A Addr dbg_vtophys(Addr addr); 1442SN/A 1452SN/A bool interval_stats; 1462SN/A#endif 1472SN/A 1482SN/A // current instruction 1494181Sgblack@eecs.umich.edu TheISA::MachInst inst; 1504181Sgblack@eecs.umich.edu 1514182Sgblack@eecs.umich.edu // The predecoder 1524182Sgblack@eecs.umich.edu TheISA::Predecoder predecoder; 1532SN/A 1542107SN/A StaticInstPtr curStaticInst; 1553276Sgblack@eecs.umich.edu StaticInstPtr curMacroStaticInst; 1561469SN/A 1574377Sgblack@eecs.umich.edu //This is the offset from the current pc that fetch should be performed at 1584377Sgblack@eecs.umich.edu Addr fetchOffset; 1594377Sgblack@eecs.umich.edu //This flag says to stay at the current pc. This is useful for 1604377Sgblack@eecs.umich.edu //instructions which go beyond MachInst boundaries. 1614377Sgblack@eecs.umich.edu bool stayAtPC; 1624377Sgblack@eecs.umich.edu 1632623SN/A void checkForInterrupts(); 1645894Sgblack@eecs.umich.edu void setupFetchRequest(Request *req); 1652623SN/A void preExecute(); 1662623SN/A void postExecute(); 1672623SN/A void advancePC(Fault fault); 168180SN/A 169393SN/A virtual void deallocateContext(int thread_num); 170393SN/A virtual void haltContext(int thread_num); 1712SN/A 1722SN/A // statistics 173334SN/A virtual void regStats(); 174334SN/A virtual void resetStats(); 1752SN/A 1762SN/A // number of simulated instructions 1772SN/A Counter numInst; 178334SN/A Counter startNumInst; 1795999Snate@binkert.org Stats::Scalar numInsts; 180707SN/A 1814998Sgblack@eecs.umich.edu void countInst() 1824998Sgblack@eecs.umich.edu { 1834998Sgblack@eecs.umich.edu numInst++; 1844998Sgblack@eecs.umich.edu numInsts++; 1857897Shestness@cs.utexas.edu system->totalNumInsts++; 1864998Sgblack@eecs.umich.edu thread->funcExeInst++; 1874998Sgblack@eecs.umich.edu } 1884998Sgblack@eecs.umich.edu 189707SN/A virtual Counter totalInstructions() const 190707SN/A { 191707SN/A return numInst - startNumInst; 192707SN/A } 1932SN/A 1947897Shestness@cs.utexas.edu //number of integer alu accesses 1957897Shestness@cs.utexas.edu Stats::Scalar numIntAluAccesses; 1967897Shestness@cs.utexas.edu 1977897Shestness@cs.utexas.edu //number of float alu accesses 1987897Shestness@cs.utexas.edu Stats::Scalar numFpAluAccesses; 1997897Shestness@cs.utexas.edu 2007897Shestness@cs.utexas.edu //number of function calls/returns 2017897Shestness@cs.utexas.edu Stats::Scalar numCallsReturns; 2027897Shestness@cs.utexas.edu 2037897Shestness@cs.utexas.edu //conditional control instructions; 2047897Shestness@cs.utexas.edu Stats::Scalar numCondCtrlInsts; 2057897Shestness@cs.utexas.edu 2067897Shestness@cs.utexas.edu //number of int instructions 2077897Shestness@cs.utexas.edu Stats::Scalar numIntInsts; 2087897Shestness@cs.utexas.edu 2097897Shestness@cs.utexas.edu //number of float instructions 2107897Shestness@cs.utexas.edu Stats::Scalar numFpInsts; 2117897Shestness@cs.utexas.edu 2127897Shestness@cs.utexas.edu //number of integer register file accesses 2137897Shestness@cs.utexas.edu Stats::Scalar numIntRegReads; 2147897Shestness@cs.utexas.edu Stats::Scalar numIntRegWrites; 2157897Shestness@cs.utexas.edu 2167897Shestness@cs.utexas.edu //number of float register file accesses 2177897Shestness@cs.utexas.edu Stats::Scalar numFpRegReads; 2187897Shestness@cs.utexas.edu Stats::Scalar numFpRegWrites; 2197897Shestness@cs.utexas.edu 2202SN/A // number of simulated memory references 2215999Snate@binkert.org Stats::Scalar numMemRefs; 2227897Shestness@cs.utexas.edu Stats::Scalar numLoadInsts; 2237897Shestness@cs.utexas.edu Stats::Scalar numStoreInsts; 2247897Shestness@cs.utexas.edu 2257897Shestness@cs.utexas.edu // number of idle cycles 2267897Shestness@cs.utexas.edu Stats::Formula numIdleCycles; 2277897Shestness@cs.utexas.edu 2287897Shestness@cs.utexas.edu // number of busy cycles 2297897Shestness@cs.utexas.edu Stats::Formula numBusyCycles; 2302SN/A 231124SN/A // number of simulated loads 232124SN/A Counter numLoad; 233334SN/A Counter startNumLoad; 234124SN/A 2352SN/A // number of idle cycles 2365999Snate@binkert.org Stats::Average notIdleFraction; 237729SN/A Stats::Formula idleFraction; 2382SN/A 2392390SN/A // number of cycles stalled for I-cache responses 2405999Snate@binkert.org Stats::Scalar icacheStallCycles; 2412SN/A Counter lastIcacheStall; 2422SN/A 2432390SN/A // number of cycles stalled for I-cache retries 2445999Snate@binkert.org Stats::Scalar icacheRetryCycles; 2452390SN/A Counter lastIcacheRetry; 2462390SN/A 2472390SN/A // number of cycles stalled for D-cache responses 2485999Snate@binkert.org Stats::Scalar dcacheStallCycles; 2492SN/A Counter lastDcacheStall; 2502SN/A 2512390SN/A // number of cycles stalled for D-cache retries 2525999Snate@binkert.org Stats::Scalar dcacheRetryCycles; 2532390SN/A Counter lastDcacheRetry; 2542390SN/A 255217SN/A virtual void serialize(std::ostream &os); 256237SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 2572SN/A 2581371SN/A // These functions are only used in CPU models that split 2591371SN/A // effective address computation from the actual memory access. 2602623SN/A void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); } 2615543Ssaidi@eecs.umich.edu Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n"); 2623918Ssaidi@eecs.umich.edu M5_DUMMY_RETURN} 2631371SN/A 264726SN/A // The register accessor methods provide the index of the 265726SN/A // instruction's operand (e.g., 0 or 1), not the architectural 266726SN/A // register index, to simplify the implementation of register 267726SN/A // renaming. We find the architectural register index by indexing 268726SN/A // into the instruction's own operand index table. Note that a 269726SN/A // raw pointer to the StaticInst is provided instead of a 270726SN/A // ref-counted StaticInstPtr to redice overhead. This is fine as 271726SN/A // long as these methods don't copy the pointer into any long-term 272726SN/A // storage (which is pretty hard to imagine they would have reason 273726SN/A // to do). 274705SN/A 2753735Sstever@eecs.umich.edu uint64_t readIntRegOperand(const StaticInst *si, int idx) 276726SN/A { 2777897Shestness@cs.utexas.edu numIntRegReads++; 2782683Sktlim@umich.edu return thread->readIntReg(si->srcRegIdx(idx)); 279726SN/A } 280705SN/A 2813735Sstever@eecs.umich.edu FloatReg readFloatRegOperand(const StaticInst *si, int idx) 282726SN/A { 2837897Shestness@cs.utexas.edu numFpRegReads++; 284726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2852683Sktlim@umich.edu return thread->readFloatReg(reg_idx); 286726SN/A } 287705SN/A 2883735Sstever@eecs.umich.edu FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) 2892455SN/A { 2907897Shestness@cs.utexas.edu numFpRegReads++; 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 { 2977897Shestness@cs.utexas.edu numIntRegWrites++; 2982683Sktlim@umich.edu thread->setIntReg(si->destRegIdx(idx), val); 299726SN/A } 300705SN/A 3013735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) 302726SN/A { 3037897Shestness@cs.utexas.edu numFpRegWrites++; 304726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3052683Sktlim@umich.edu thread->setFloatReg(reg_idx, val); 306726SN/A } 307726SN/A 3083735Sstever@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 3093735Sstever@eecs.umich.edu FloatRegBits val) 3102455SN/A { 3117897Shestness@cs.utexas.edu numFpRegWrites++; 3122455SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 3132683Sktlim@umich.edu thread->setFloatRegBits(reg_idx, val); 314726SN/A } 315705SN/A 3167597Sminkyu.jeong@arm.com bool readPredicate() { return thread->readPredicate(); } 3177597Sminkyu.jeong@arm.com void setPredicate(bool val) 3187600Sminkyu.jeong@arm.com { 3197600Sminkyu.jeong@arm.com thread->setPredicate(val); 3207600Sminkyu.jeong@arm.com if (traceData) { 3217600Sminkyu.jeong@arm.com traceData->setPredicate(val); 3227600Sminkyu.jeong@arm.com } 3237600Sminkyu.jeong@arm.com } 3247720Sgblack@eecs.umich.edu TheISA::PCState pcState() { return thread->pcState(); } 3257720Sgblack@eecs.umich.edu void pcState(const TheISA::PCState &val) { thread->pcState(val); } 3267720Sgblack@eecs.umich.edu Addr instAddr() { return thread->instAddr(); } 3277720Sgblack@eecs.umich.edu Addr nextInstAddr() { return thread->nextInstAddr(); } 3287720Sgblack@eecs.umich.edu MicroPC microPC() { return thread->microPC(); } 329705SN/A 3304172Ssaidi@eecs.umich.edu MiscReg readMiscRegNoEffect(int misc_reg) 3314172Ssaidi@eecs.umich.edu { 3324172Ssaidi@eecs.umich.edu return thread->readMiscRegNoEffect(misc_reg); 3334172Ssaidi@eecs.umich.edu } 3344172Ssaidi@eecs.umich.edu 3352159SN/A MiscReg readMiscReg(int misc_reg) 3362159SN/A { 3377897Shestness@cs.utexas.edu numIntRegReads++; 3382683Sktlim@umich.edu return thread->readMiscReg(misc_reg); 3392159SN/A } 340705SN/A 3413468Sgblack@eecs.umich.edu void setMiscReg(int misc_reg, const MiscReg &val) 3422159SN/A { 3437897Shestness@cs.utexas.edu numIntRegWrites++; 3442683Sktlim@umich.edu return thread->setMiscReg(misc_reg, val); 3452159SN/A } 3462159SN/A 3474185Ssaidi@eecs.umich.edu MiscReg readMiscRegOperand(const StaticInst *si, int idx) 3483792Sgblack@eecs.umich.edu { 3497897Shestness@cs.utexas.edu numIntRegReads++; 3503792Sgblack@eecs.umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3513792Sgblack@eecs.umich.edu return thread->readMiscReg(reg_idx); 3523792Sgblack@eecs.umich.edu } 3533792Sgblack@eecs.umich.edu 3544185Ssaidi@eecs.umich.edu void setMiscRegOperand( 3553792Sgblack@eecs.umich.edu const StaticInst *si, int idx, const MiscReg &val) 3563792Sgblack@eecs.umich.edu { 3577897Shestness@cs.utexas.edu numIntRegWrites++; 3583792Sgblack@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag; 3594172Ssaidi@eecs.umich.edu return thread->setMiscReg(reg_idx, val); 3603792Sgblack@eecs.umich.edu } 3613792Sgblack@eecs.umich.edu 3625358Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 3635358Sgblack@eecs.umich.edu { 3645358Sgblack@eecs.umich.edu thread->demapPage(vaddr, asn); 3655358Sgblack@eecs.umich.edu } 3665358Sgblack@eecs.umich.edu 3675358Sgblack@eecs.umich.edu void demapInstPage(Addr vaddr, uint64_t asn) 3685358Sgblack@eecs.umich.edu { 3695358Sgblack@eecs.umich.edu thread->demapInstPage(vaddr, asn); 3705358Sgblack@eecs.umich.edu } 3715358Sgblack@eecs.umich.edu 3725358Sgblack@eecs.umich.edu void demapDataPage(Addr vaddr, uint64_t asn) 3735358Sgblack@eecs.umich.edu { 3745358Sgblack@eecs.umich.edu thread->demapDataPage(vaddr, asn); 3755358Sgblack@eecs.umich.edu } 3765358Sgblack@eecs.umich.edu 3774027Sstever@eecs.umich.edu unsigned readStCondFailures() { 3784027Sstever@eecs.umich.edu return thread->readStCondFailures(); 3794027Sstever@eecs.umich.edu } 3804027Sstever@eecs.umich.edu 3814027Sstever@eecs.umich.edu void setStCondFailures(unsigned sc_failures) { 3824027Sstever@eecs.umich.edu thread->setStCondFailures(sc_failures); 3834027Sstever@eecs.umich.edu } 3844027Sstever@eecs.umich.edu 3856221Snate@binkert.org MiscReg readRegOtherThread(int regIdx, ThreadID tid = InvalidThreadID) 3864661Sksewell@umich.edu { 3874661Sksewell@umich.edu panic("Simple CPU models do not support multithreaded " 3884661Sksewell@umich.edu "register access.\n"); 3894661Sksewell@umich.edu } 3904661Sksewell@umich.edu 3916221Snate@binkert.org void setRegOtherThread(int regIdx, const MiscReg &val, 3926221Snate@binkert.org ThreadID tid = InvalidThreadID) 3934661Sksewell@umich.edu { 3944661Sksewell@umich.edu panic("Simple CPU models do not support multithreaded " 3954661Sksewell@umich.edu "register access.\n"); 3964661Sksewell@umich.edu } 3974661Sksewell@umich.edu 3985250Sksewell@umich.edu //Fault CacheOp(uint8_t Op, Addr EA); 3995222Sksewell@umich.edu 4001858SN/A#if FULL_SYSTEM 4015702Ssaidi@eecs.umich.edu Fault hwrei() { return thread->hwrei(); } 4025702Ssaidi@eecs.umich.edu bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); } 403705SN/A#else 4042683Sktlim@umich.edu void syscall(int64_t callnum) { thread->syscall(callnum); } 405705SN/A#endif 406705SN/A 4072683Sktlim@umich.edu bool misspeculating() { return thread->misspeculating(); } 4082680Sktlim@umich.edu ThreadContext *tcBase() { return tc; } 4092SN/A}; 4102SN/A 4112623SN/A#endif // __CPU_SIMPLE_BASE_HH__ 412