base.hh revision 3918
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 361354SN/A#include "base/statistics.hh" 371858SN/A#include "config/full_system.hh" 381717SN/A#include "cpu/base.hh" 392683Sktlim@umich.edu#include "cpu/simple_thread.hh" 401354SN/A#include "cpu/pc_event.hh" 411354SN/A#include "cpu/static_inst.hh" 422387SN/A#include "mem/packet.hh" 432387SN/A#include "mem/port.hh" 442387SN/A#include "mem/request.hh" 4556SN/A#include "sim/eventq.hh" 462SN/A 472SN/A// forward declarations 481858SN/A#if FULL_SYSTEM 492SN/Aclass Processor; 503453Sgblack@eecs.umich.edunamespace TheISA 513453Sgblack@eecs.umich.edu{ 523453Sgblack@eecs.umich.edu class ITB; 533453Sgblack@eecs.umich.edu class DTB; 543453Sgblack@eecs.umich.edu} 552462SN/Aclass MemObject; 562SN/A 572SN/Aclass RemoteGDB; 582SN/Aclass GDBListener; 59715SN/A 60715SN/A#else 61715SN/A 62715SN/Aclass Process; 63715SN/A 642SN/A#endif // FULL_SYSTEM 652SN/A 662680Sktlim@umich.educlass ThreadContext; 67237SN/Aclass Checkpoint; 682SN/A 692SN/Anamespace Trace { 702SN/A class InstRecord; 712SN/A} 722SN/A 732420SN/A 742623SN/Aclass BaseSimpleCPU : public BaseCPU 752SN/A{ 762107SN/A protected: 772107SN/A typedef TheISA::MachInst MachInst; 782159SN/A typedef TheISA::MiscReg MiscReg; 792455SN/A typedef TheISA::FloatReg FloatReg; 802455SN/A typedef TheISA::FloatRegBits FloatRegBits; 812386SN/A 822623SN/A protected: 832SN/A Trace::InstRecord *traceData; 841371SN/A 852SN/A public: 862SN/A void post_interrupt(int int_num, int index); 872SN/A 882SN/A void zero_fill_64(Addr addr) { 892SN/A static int warned = 0; 902SN/A if (!warned) { 912SN/A warn ("WH64 is not implemented"); 922SN/A warned = 1; 932SN/A } 942SN/A }; 952SN/A 961400SN/A public: 971400SN/A struct Params : public BaseCPU::Params 981400SN/A { 991858SN/A#if FULL_SYSTEM 1003453Sgblack@eecs.umich.edu TheISA::ITB *itb; 1013453Sgblack@eecs.umich.edu TheISA::DTB *dtb; 1022SN/A#else 1031400SN/A Process *process; 1042SN/A#endif 1051400SN/A }; 1062623SN/A BaseSimpleCPU(Params *params); 1072623SN/A virtual ~BaseSimpleCPU(); 1082SN/A 1091400SN/A public: 1102683Sktlim@umich.edu /** SimpleThread object, provides all the architectural state. */ 1112683Sktlim@umich.edu SimpleThread *thread; 1122190SN/A 1132683Sktlim@umich.edu /** ThreadContext object, provides an interface for external 1142683Sktlim@umich.edu * objects to modify this thread's state. 1152683Sktlim@umich.edu */ 1162680Sktlim@umich.edu ThreadContext *tc; 1172SN/A 1181858SN/A#if FULL_SYSTEM 1192SN/A Addr dbg_vtophys(Addr addr); 1202SN/A 1212SN/A bool interval_stats; 1222SN/A#endif 1232SN/A 1242SN/A // current instruction 1252SN/A MachInst inst; 1262SN/A 1272566SN/A // Static data storage 1282566SN/A TheISA::IntReg dataReg; 1292566SN/A 1302107SN/A StaticInstPtr curStaticInst; 1313276Sgblack@eecs.umich.edu StaticInstPtr curMacroStaticInst; 1321469SN/A 1332623SN/A void checkForInterrupts(); 1342662Sstever@eecs.umich.edu Fault setupFetchRequest(Request *req); 1352623SN/A void preExecute(); 1362623SN/A void postExecute(); 1372623SN/A void advancePC(Fault fault); 138180SN/A 139393SN/A virtual void deallocateContext(int thread_num); 140393SN/A virtual void haltContext(int thread_num); 1412SN/A 1422SN/A // statistics 143334SN/A virtual void regStats(); 144334SN/A virtual void resetStats(); 1452SN/A 1462SN/A // number of simulated instructions 1472SN/A Counter numInst; 148334SN/A Counter startNumInst; 149729SN/A Stats::Scalar<> numInsts; 150707SN/A 151707SN/A virtual Counter totalInstructions() const 152707SN/A { 153707SN/A return numInst - startNumInst; 154707SN/A } 1552SN/A 1562SN/A // number of simulated memory references 157729SN/A Stats::Scalar<> numMemRefs; 1582SN/A 159124SN/A // number of simulated loads 160124SN/A Counter numLoad; 161334SN/A Counter startNumLoad; 162124SN/A 1632SN/A // number of idle cycles 164729SN/A Stats::Average<> notIdleFraction; 165729SN/A Stats::Formula idleFraction; 1662SN/A 1672390SN/A // number of cycles stalled for I-cache responses 168729SN/A Stats::Scalar<> icacheStallCycles; 1692SN/A Counter lastIcacheStall; 1702SN/A 1712390SN/A // number of cycles stalled for I-cache retries 1722390SN/A Stats::Scalar<> icacheRetryCycles; 1732390SN/A Counter lastIcacheRetry; 1742390SN/A 1752390SN/A // number of cycles stalled for D-cache responses 176729SN/A Stats::Scalar<> dcacheStallCycles; 1772SN/A Counter lastDcacheStall; 1782SN/A 1792390SN/A // number of cycles stalled for D-cache retries 1802390SN/A Stats::Scalar<> dcacheRetryCycles; 1812390SN/A Counter lastDcacheRetry; 1822390SN/A 183217SN/A virtual void serialize(std::ostream &os); 184237SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 1852SN/A 1861371SN/A // These functions are only used in CPU models that split 1871371SN/A // effective address computation from the actual memory access. 1882623SN/A void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); } 1893918Ssaidi@eecs.umich.edu Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n"); 1903918Ssaidi@eecs.umich.edu M5_DUMMY_RETURN} 1911371SN/A 192581SN/A void prefetch(Addr addr, unsigned flags) 1932SN/A { 1942SN/A // need to do this... 1952SN/A } 1962SN/A 197753SN/A void writeHint(Addr addr, int size, unsigned flags) 1982SN/A { 1992SN/A // need to do this... 2002SN/A } 201594SN/A 202595SN/A Fault copySrcTranslate(Addr src); 203594SN/A 204595SN/A Fault copy(Addr dest); 205705SN/A 206726SN/A // The register accessor methods provide the index of the 207726SN/A // instruction's operand (e.g., 0 or 1), not the architectural 208726SN/A // register index, to simplify the implementation of register 209726SN/A // renaming. We find the architectural register index by indexing 210726SN/A // into the instruction's own operand index table. Note that a 211726SN/A // raw pointer to the StaticInst is provided instead of a 212726SN/A // ref-counted StaticInstPtr to redice overhead. This is fine as 213726SN/A // long as these methods don't copy the pointer into any long-term 214726SN/A // storage (which is pretty hard to imagine they would have reason 215726SN/A // to do). 216705SN/A 2173735Sstever@eecs.umich.edu uint64_t readIntRegOperand(const StaticInst *si, int idx) 218726SN/A { 2192683Sktlim@umich.edu return thread->readIntReg(si->srcRegIdx(idx)); 220726SN/A } 221705SN/A 2223735Sstever@eecs.umich.edu FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width) 223726SN/A { 224726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2252683Sktlim@umich.edu return thread->readFloatReg(reg_idx, width); 226726SN/A } 227705SN/A 2283735Sstever@eecs.umich.edu FloatReg readFloatRegOperand(const StaticInst *si, int idx) 229726SN/A { 230726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2312683Sktlim@umich.edu return thread->readFloatReg(reg_idx); 232726SN/A } 233705SN/A 2343735Sstever@eecs.umich.edu FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx, 2353735Sstever@eecs.umich.edu int width) 236726SN/A { 237726SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2382683Sktlim@umich.edu return thread->readFloatRegBits(reg_idx, width); 2392455SN/A } 2402455SN/A 2413735Sstever@eecs.umich.edu FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) 2422455SN/A { 2432455SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag; 2442683Sktlim@umich.edu return thread->readFloatRegBits(reg_idx); 245726SN/A } 246705SN/A 2473735Sstever@eecs.umich.edu void setIntRegOperand(const StaticInst *si, int idx, uint64_t val) 248726SN/A { 2492683Sktlim@umich.edu thread->setIntReg(si->destRegIdx(idx), val); 250726SN/A } 251705SN/A 2523735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val, 2533735Sstever@eecs.umich.edu int width) 254726SN/A { 255726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2562683Sktlim@umich.edu thread->setFloatReg(reg_idx, val, width); 257726SN/A } 258705SN/A 2593735Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) 260726SN/A { 261726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2622683Sktlim@umich.edu thread->setFloatReg(reg_idx, val); 263726SN/A } 264726SN/A 2653735Sstever@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 2663735Sstever@eecs.umich.edu FloatRegBits val, int width) 267726SN/A { 268726SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2692683Sktlim@umich.edu thread->setFloatRegBits(reg_idx, val, width); 2702455SN/A } 2712455SN/A 2723735Sstever@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 2733735Sstever@eecs.umich.edu FloatRegBits val) 2742455SN/A { 2752455SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag; 2762683Sktlim@umich.edu thread->setFloatRegBits(reg_idx, val); 277726SN/A } 278705SN/A 2792683Sktlim@umich.edu uint64_t readPC() { return thread->readPC(); } 2802683Sktlim@umich.edu uint64_t readNextPC() { return thread->readNextPC(); } 2812683Sktlim@umich.edu uint64_t readNextNPC() { return thread->readNextNPC(); } 2822447SN/A 2832683Sktlim@umich.edu void setPC(uint64_t val) { thread->setPC(val); } 2842683Sktlim@umich.edu void setNextPC(uint64_t val) { thread->setNextPC(val); } 2852683Sktlim@umich.edu void setNextNPC(uint64_t val) { thread->setNextNPC(val); } 286705SN/A 2872159SN/A MiscReg readMiscReg(int misc_reg) 2882159SN/A { 2892683Sktlim@umich.edu return thread->readMiscReg(misc_reg); 2902159SN/A } 291705SN/A 2923468Sgblack@eecs.umich.edu MiscReg readMiscRegWithEffect(int misc_reg) 2932159SN/A { 2943468Sgblack@eecs.umich.edu return thread->readMiscRegWithEffect(misc_reg); 2952159SN/A } 2962159SN/A 2973468Sgblack@eecs.umich.edu void setMiscReg(int misc_reg, const MiscReg &val) 2982159SN/A { 2992683Sktlim@umich.edu return thread->setMiscReg(misc_reg, val); 3002159SN/A } 3012159SN/A 3023468Sgblack@eecs.umich.edu void setMiscRegWithEffect(int misc_reg, const MiscReg &val) 3032159SN/A { 3042683Sktlim@umich.edu return thread->setMiscRegWithEffect(misc_reg, val); 3052159SN/A } 306705SN/A 3071858SN/A#if FULL_SYSTEM 3082683Sktlim@umich.edu Fault hwrei() { return thread->hwrei(); } 3092680Sktlim@umich.edu void ev5_trap(Fault fault) { fault->invoke(tc); } 3102683Sktlim@umich.edu bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); } 311705SN/A#else 3122683Sktlim@umich.edu void syscall(int64_t callnum) { thread->syscall(callnum); } 313705SN/A#endif 314705SN/A 3152683Sktlim@umich.edu bool misspeculating() { return thread->misspeculating(); } 3162680Sktlim@umich.edu ThreadContext *tcBase() { return tc; } 3172SN/A}; 3182SN/A 3192623SN/A#endif // __CPU_SIMPLE_BASE_HH__ 320