base_dyn_inst.hh revision 3093
11060SN/A/* 22702Sktlim@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan 31060SN/A * All rights reserved. 41060SN/A * 51060SN/A * Redistribution and use in source and binary forms, with or without 61060SN/A * modification, are permitted provided that the following conditions are 71060SN/A * met: redistributions of source code must retain the above copyright 81060SN/A * notice, this list of conditions and the following disclaimer; 91060SN/A * redistributions in binary form must reproduce the above copyright 101060SN/A * notice, this list of conditions and the following disclaimer in the 111060SN/A * documentation and/or other materials provided with the distribution; 121060SN/A * neither the name of the copyright holders nor the names of its 131060SN/A * contributors may be used to endorse or promote products derived from 141060SN/A * this software without specific prior written permission. 151060SN/A * 161060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 291060SN/A */ 301060SN/A 311464SN/A#ifndef __CPU_BASE_DYN_INST_HH__ 321464SN/A#define __CPU_BASE_DYN_INST_HH__ 331060SN/A 342731Sktlim@umich.edu#include <bitset> 352292SN/A#include <list> 361464SN/A#include <string> 371060SN/A 382669Sktlim@umich.edu#include "arch/faults.hh" 391060SN/A#include "base/fast_alloc.hh" 401060SN/A#include "base/trace.hh" 411858SN/A#include "config/full_system.hh" 421464SN/A#include "cpu/exetrace.hh" 431464SN/A#include "cpu/inst_seq.hh" 442669Sktlim@umich.edu#include "cpu/op_class.hh" 451060SN/A#include "cpu/static_inst.hh" 462669Sktlim@umich.edu#include "mem/packet.hh" 472292SN/A#include "sim/system.hh" 481060SN/A 491060SN/A/** 501060SN/A * @file 511060SN/A * Defines a dynamic instruction context. 521060SN/A */ 531060SN/A 541061SN/A// Forward declaration. 551061SN/Aclass StaticInstPtr; 561060SN/A 571060SN/Atemplate <class Impl> 581061SN/Aclass BaseDynInst : public FastAlloc, public RefCounted 591060SN/A{ 601060SN/A public: 611060SN/A // Typedef for the CPU. 622733Sktlim@umich.edu typedef typename Impl::CPUType ImplCPU; 632733Sktlim@umich.edu typedef typename ImplCPU::ImplState ImplState; 641060SN/A 652292SN/A // Binary machine instruction type. 662107SN/A typedef TheISA::MachInst MachInst; 672292SN/A // Extended machine instruction type 682292SN/A typedef TheISA::ExtMachInst ExtMachInst; 692292SN/A // Logical register index type. 702107SN/A typedef TheISA::RegIndex RegIndex; 712690Sktlim@umich.edu // Integer register type. 722107SN/A typedef TheISA::IntReg IntReg; 732690Sktlim@umich.edu // Floating point register type. 742690Sktlim@umich.edu typedef TheISA::FloatReg FloatReg; 751060SN/A 762292SN/A // The DynInstPtr type. 772292SN/A typedef typename Impl::DynInstPtr DynInstPtr; 782292SN/A 792292SN/A // The list of instructions iterator type. 802292SN/A typedef typename std::list<DynInstPtr>::iterator ListIt; 812292SN/A 821060SN/A enum { 832292SN/A MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs 842292SN/A MaxInstDestRegs = TheISA::MaxInstDestRegs, /// Max dest regs 851060SN/A }; 861060SN/A 872292SN/A /** The StaticInst used by this BaseDynInst. */ 882107SN/A StaticInstPtr staticInst; 891060SN/A 901060SN/A //////////////////////////////////////////// 911060SN/A // 921060SN/A // INSTRUCTION EXECUTION 931060SN/A // 941060SN/A //////////////////////////////////////////// 952292SN/A /** InstRecord that tracks this instructions. */ 961060SN/A Trace::InstRecord *traceData; 971060SN/A 982292SN/A /** 992292SN/A * Does a read to a given address. 1002292SN/A * @param addr The address to read. 1012292SN/A * @param data The read's data is written into this parameter. 1022292SN/A * @param flags The request's flags. 1032292SN/A * @return Returns any fault due to the read. 1042292SN/A */ 1051060SN/A template <class T> 1062132SN/A Fault read(Addr addr, T &data, unsigned flags); 1071060SN/A 1082292SN/A /** 1092292SN/A * Does a write to a given address. 1102292SN/A * @param data The data to be written. 1112292SN/A * @param addr The address to write to. 1122292SN/A * @param flags The request's flags. 1132292SN/A * @param res The result of the write (for load locked/store conditionals). 1142292SN/A * @return Returns any fault due to the write. 1152292SN/A */ 1161060SN/A template <class T> 1172132SN/A Fault write(T data, Addr addr, unsigned flags, 1181060SN/A uint64_t *res); 1191060SN/A 1201060SN/A void prefetch(Addr addr, unsigned flags); 1211060SN/A void writeHint(Addr addr, int size, unsigned flags); 1222132SN/A Fault copySrcTranslate(Addr src); 1232132SN/A Fault copy(Addr dest); 1241060SN/A 1251684SN/A /** @todo: Consider making this private. */ 1261060SN/A public: 1271060SN/A /** The sequence number of the instruction. */ 1281060SN/A InstSeqNum seqNum; 1291060SN/A 1302731Sktlim@umich.edu enum Status { 1312731Sktlim@umich.edu IqEntry, /// Instruction is in the IQ 1322731Sktlim@umich.edu RobEntry, /// Instruction is in the ROB 1332731Sktlim@umich.edu LsqEntry, /// Instruction is in the LSQ 1342731Sktlim@umich.edu Completed, /// Instruction has completed 1352731Sktlim@umich.edu ResultReady, /// Instruction has its result 1362731Sktlim@umich.edu CanIssue, /// Instruction can issue and execute 1372731Sktlim@umich.edu Issued, /// Instruction has issued 1382731Sktlim@umich.edu Executed, /// Instruction has executed 1392731Sktlim@umich.edu CanCommit, /// Instruction can commit 1402731Sktlim@umich.edu AtCommit, /// Instruction has reached commit 1412731Sktlim@umich.edu Committed, /// Instruction has committed 1422731Sktlim@umich.edu Squashed, /// Instruction is squashed 1432731Sktlim@umich.edu SquashedInIQ, /// Instruction is squashed in the IQ 1442731Sktlim@umich.edu SquashedInLSQ, /// Instruction is squashed in the LSQ 1452731Sktlim@umich.edu SquashedInROB, /// Instruction is squashed in the ROB 1462731Sktlim@umich.edu RecoverInst, /// Is a recover instruction 1472731Sktlim@umich.edu BlockingInst, /// Is a blocking instruction 1482731Sktlim@umich.edu ThreadsyncWait, /// Is a thread synchronization instruction 1492731Sktlim@umich.edu SerializeBefore, /// Needs to serialize on 1502731Sktlim@umich.edu /// instructions ahead of it 1512731Sktlim@umich.edu SerializeAfter, /// Needs to serialize instructions behind it 1522731Sktlim@umich.edu SerializeHandled, /// Serialization has been handled 1532731Sktlim@umich.edu NumStatus 1542731Sktlim@umich.edu }; 1552292SN/A 1562731Sktlim@umich.edu /** The status of this BaseDynInst. Several bits can be set. */ 1572731Sktlim@umich.edu std::bitset<NumStatus> status; 1581060SN/A 1591060SN/A /** The thread this instruction is from. */ 1601060SN/A short threadNumber; 1611060SN/A 1621060SN/A /** data address space ID, for loads & stores. */ 1631060SN/A short asid; 1641060SN/A 1652292SN/A /** How many source registers are ready. */ 1662292SN/A unsigned readyRegs; 1672292SN/A 1682733Sktlim@umich.edu /** Pointer to the Impl's CPU object. */ 1692733Sktlim@umich.edu ImplCPU *cpu; 1701060SN/A 1712680Sktlim@umich.edu /** Pointer to the thread state. */ 1722292SN/A ImplState *thread; 1731060SN/A 1741060SN/A /** The kind of fault this instruction has generated. */ 1752132SN/A Fault fault; 1761060SN/A 1772292SN/A /** The memory request. */ 1782669Sktlim@umich.edu Request *req; 1792669Sktlim@umich.edu 1802702Sktlim@umich.edu /** Pointer to the data for the memory access. */ 1812669Sktlim@umich.edu uint8_t *memData; 1822292SN/A 1831060SN/A /** The effective virtual address (lds & stores only). */ 1841060SN/A Addr effAddr; 1851060SN/A 1861060SN/A /** The effective physical address. */ 1871060SN/A Addr physEffAddr; 1881060SN/A 1891060SN/A /** Effective virtual address for a copy source. */ 1901060SN/A Addr copySrcEffAddr; 1911060SN/A 1921060SN/A /** Effective physical address for a copy source. */ 1931060SN/A Addr copySrcPhysEffAddr; 1941060SN/A 1951060SN/A /** The memory request flags (from translation). */ 1961060SN/A unsigned memReqFlags; 1971060SN/A 1981464SN/A union Result { 1991464SN/A uint64_t integer; 2001464SN/A float fp; 2011464SN/A double dbl; 2021464SN/A }; 2031060SN/A 2041464SN/A /** The result of the instruction; assumes for now that there's only one 2051464SN/A * destination register. 2061464SN/A */ 2071464SN/A Result instResult; 2081060SN/A 2091060SN/A /** PC of this instruction. */ 2101060SN/A Addr PC; 2111060SN/A 2121060SN/A /** Next non-speculative PC. It is not filled in at fetch, but rather 2131060SN/A * once the target of the branch is truly known (either decode or 2141060SN/A * execute). 2151060SN/A */ 2161060SN/A Addr nextPC; 2171060SN/A 2182935Sksewell@umich.edu /** Next non-speculative NPC. Target PC for Mips or Sparc. */ 2192935Sksewell@umich.edu Addr nextNPC; 2202935Sksewell@umich.edu 2211060SN/A /** Predicted next PC. */ 2221060SN/A Addr predPC; 2231060SN/A 2241060SN/A /** Count of total number of dynamic instructions. */ 2251060SN/A static int instcount; 2261060SN/A 2272292SN/A#ifdef DEBUG 2282292SN/A void dumpSNList(); 2292292SN/A#endif 2302292SN/A 2312292SN/A /** Whether or not the source register is ready. 2322292SN/A * @todo: Not sure this should be here vs the derived class. 2331060SN/A */ 2341060SN/A bool _readySrcRegIdx[MaxInstSrcRegs]; 2351060SN/A 2361060SN/A public: 2372292SN/A /** BaseDynInst constructor given a binary instruction. 2382292SN/A * @param inst The binary instruction. 2392292SN/A * @param PC The PC of the instruction. 2402292SN/A * @param pred_PC The predicted next PC. 2412292SN/A * @param seq_num The sequence number of the instruction. 2422292SN/A * @param cpu Pointer to the instruction's CPU. 2432292SN/A */ 2442292SN/A BaseDynInst(ExtMachInst inst, Addr PC, Addr pred_PC, InstSeqNum seq_num, 2452733Sktlim@umich.edu ImplCPU *cpu); 2461060SN/A 2472292SN/A /** BaseDynInst constructor given a StaticInst pointer. 2482292SN/A * @param _staticInst The StaticInst for this BaseDynInst. 2492292SN/A */ 2502107SN/A BaseDynInst(StaticInstPtr &_staticInst); 2511060SN/A 2521060SN/A /** BaseDynInst destructor. */ 2531060SN/A ~BaseDynInst(); 2541060SN/A 2551464SN/A private: 2561684SN/A /** Function to initialize variables in the constructors. */ 2571464SN/A void initVars(); 2581060SN/A 2591464SN/A public: 2601060SN/A /** Dumps out contents of this BaseDynInst. */ 2611060SN/A void dump(); 2621060SN/A 2631060SN/A /** Dumps out contents of this BaseDynInst into given string. */ 2641060SN/A void dump(std::string &outstring); 2651060SN/A 2661060SN/A /** Returns the fault type. */ 2672132SN/A Fault getFault() { return fault; } 2681060SN/A 2691060SN/A /** Checks whether or not this instruction has had its branch target 2701060SN/A * calculated yet. For now it is not utilized and is hacked to be 2711060SN/A * always false. 2722292SN/A * @todo: Actually use this instruction. 2731060SN/A */ 2741060SN/A bool doneTargCalc() { return false; } 2751060SN/A 2761684SN/A /** Returns the next PC. This could be the speculative next PC if it is 2771684SN/A * called prior to the actual branch target being calculated. 2781684SN/A */ 2791060SN/A Addr readNextPC() { return nextPC; } 2801060SN/A 2812935Sksewell@umich.edu /** Returns the next NPC. This could be the speculative next NPC if it is 2822935Sksewell@umich.edu * called prior to the actual branch target being calculated. 2832935Sksewell@umich.edu */ 2842935Sksewell@umich.edu Addr readNextNPC() { return nextNPC; } 2852935Sksewell@umich.edu 2861060SN/A /** Set the predicted target of this current instruction. */ 2871060SN/A void setPredTarg(Addr predicted_PC) { predPC = predicted_PC; } 2881060SN/A 2891060SN/A /** Returns the predicted target of the branch. */ 2901060SN/A Addr readPredTarg() { return predPC; } 2911060SN/A 2921060SN/A /** Returns whether the instruction was predicted taken or not. */ 2932935Sksewell@umich.edu bool predTaken() 2943093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 2953093Sksewell@umich.edu { return predPC != (nextPC + sizeof(MachInst)); } 2963093Sksewell@umich.edu#else 2972935Sksewell@umich.edu { return predPC != (PC + sizeof(MachInst)); } 2982935Sksewell@umich.edu#endif 2991060SN/A 3001060SN/A /** Returns whether the instruction mispredicted. */ 3012935Sksewell@umich.edu bool mispredicted() 3023093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 3033093Sksewell@umich.edu { return predPC != nextNPC; } 3043093Sksewell@umich.edu#else 3052935Sksewell@umich.edu { return predPC != nextPC; } 3062935Sksewell@umich.edu#endif 3071060SN/A // 3081060SN/A // Instruction types. Forward checks to StaticInst object. 3091060SN/A // 3101060SN/A bool isNop() const { return staticInst->isNop(); } 3111060SN/A bool isMemRef() const { return staticInst->isMemRef(); } 3121060SN/A bool isLoad() const { return staticInst->isLoad(); } 3131060SN/A bool isStore() const { return staticInst->isStore(); } 3142336SN/A bool isStoreConditional() const 3152336SN/A { return staticInst->isStoreConditional(); } 3161060SN/A bool isInstPrefetch() const { return staticInst->isInstPrefetch(); } 3171060SN/A bool isDataPrefetch() const { return staticInst->isDataPrefetch(); } 3181060SN/A bool isCopy() const { return staticInst->isCopy(); } 3191060SN/A bool isInteger() const { return staticInst->isInteger(); } 3201060SN/A bool isFloating() const { return staticInst->isFloating(); } 3211060SN/A bool isControl() const { return staticInst->isControl(); } 3221060SN/A bool isCall() const { return staticInst->isCall(); } 3231060SN/A bool isReturn() const { return staticInst->isReturn(); } 3241060SN/A bool isDirectCtrl() const { return staticInst->isDirectCtrl(); } 3251060SN/A bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); } 3261060SN/A bool isCondCtrl() const { return staticInst->isCondCtrl(); } 3271060SN/A bool isUncondCtrl() const { return staticInst->isUncondCtrl(); } 3282935Sksewell@umich.edu bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); } 3291060SN/A bool isThreadSync() const { return staticInst->isThreadSync(); } 3301060SN/A bool isSerializing() const { return staticInst->isSerializing(); } 3312292SN/A bool isSerializeBefore() const 3322731Sktlim@umich.edu { return staticInst->isSerializeBefore() || status[SerializeBefore]; } 3332292SN/A bool isSerializeAfter() const 3342731Sktlim@umich.edu { return staticInst->isSerializeAfter() || status[SerializeAfter]; } 3351060SN/A bool isMemBarrier() const { return staticInst->isMemBarrier(); } 3361060SN/A bool isWriteBarrier() const { return staticInst->isWriteBarrier(); } 3371060SN/A bool isNonSpeculative() const { return staticInst->isNonSpeculative(); } 3382292SN/A bool isQuiesce() const { return staticInst->isQuiesce(); } 3392336SN/A bool isIprAccess() const { return staticInst->isIprAccess(); } 3402308SN/A bool isUnverifiable() const { return staticInst->isUnverifiable(); } 3412292SN/A 3422292SN/A /** Temporarily sets this instruction as a serialize before instruction. */ 3432731Sktlim@umich.edu void setSerializeBefore() { status.set(SerializeBefore); } 3442292SN/A 3452292SN/A /** Clears the serializeBefore part of this instruction. */ 3462731Sktlim@umich.edu void clearSerializeBefore() { status.reset(SerializeBefore); } 3472292SN/A 3482292SN/A /** Checks if this serializeBefore is only temporarily set. */ 3492731Sktlim@umich.edu bool isTempSerializeBefore() { return status[SerializeBefore]; } 3502292SN/A 3512292SN/A /** Temporarily sets this instruction as a serialize after instruction. */ 3522731Sktlim@umich.edu void setSerializeAfter() { status.set(SerializeAfter); } 3532292SN/A 3542292SN/A /** Clears the serializeAfter part of this instruction.*/ 3552731Sktlim@umich.edu void clearSerializeAfter() { status.reset(SerializeAfter); } 3562292SN/A 3572292SN/A /** Checks if this serializeAfter is only temporarily set. */ 3582731Sktlim@umich.edu bool isTempSerializeAfter() { return status[SerializeAfter]; } 3592292SN/A 3602731Sktlim@umich.edu /** Sets the serialization part of this instruction as handled. */ 3612731Sktlim@umich.edu void setSerializeHandled() { status.set(SerializeHandled); } 3622292SN/A 3632292SN/A /** Checks if the serialization part of this instruction has been 3642292SN/A * handled. This does not apply to the temporary serializing 3652292SN/A * state; it only applies to this instruction's own permanent 3662292SN/A * serializing state. 3672292SN/A */ 3682731Sktlim@umich.edu bool isSerializeHandled() { return status[SerializeHandled]; } 3691060SN/A 3701464SN/A /** Returns the opclass of this instruction. */ 3711464SN/A OpClass opClass() const { return staticInst->opClass(); } 3721464SN/A 3731464SN/A /** Returns the branch target address. */ 3741464SN/A Addr branchTarget() const { return staticInst->branchTarget(PC); } 3751464SN/A 3762292SN/A /** Returns the number of source registers. */ 3772292SN/A int8_t numSrcRegs() const { return staticInst->numSrcRegs(); } 3781684SN/A 3792292SN/A /** Returns the number of destination registers. */ 3801060SN/A int8_t numDestRegs() const { return staticInst->numDestRegs(); } 3811060SN/A 3821060SN/A // the following are used to track physical register usage 3831060SN/A // for machines with separate int & FP reg files 3841060SN/A int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); } 3851060SN/A int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); } 3861060SN/A 3871060SN/A /** Returns the logical register index of the i'th destination register. */ 3882292SN/A RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); } 3891060SN/A 3901060SN/A /** Returns the logical register index of the i'th source register. */ 3912292SN/A RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); } 3921060SN/A 3931684SN/A /** Returns the result of an integer instruction. */ 3941464SN/A uint64_t readIntResult() { return instResult.integer; } 3951684SN/A 3961684SN/A /** Returns the result of a floating point instruction. */ 3971464SN/A float readFloatResult() { return instResult.fp; } 3981684SN/A 3991684SN/A /** Returns the result of a floating point (double) instruction. */ 4001464SN/A double readDoubleResult() { return instResult.dbl; } 4011060SN/A 4022702Sktlim@umich.edu /** Records an integer register being set to a value. */ 4032308SN/A void setIntReg(const StaticInst *si, int idx, uint64_t val) 4041060SN/A { 4052308SN/A instResult.integer = val; 4061060SN/A } 4071060SN/A 4082702Sktlim@umich.edu /** Records an fp register being set to a value. */ 4092690Sktlim@umich.edu void setFloatReg(const StaticInst *si, int idx, FloatReg val, int width) 4102690Sktlim@umich.edu { 4112690Sktlim@umich.edu if (width == 32) 4122690Sktlim@umich.edu instResult.fp = val; 4132690Sktlim@umich.edu else if (width == 64) 4142690Sktlim@umich.edu instResult.dbl = val; 4152690Sktlim@umich.edu else 4162690Sktlim@umich.edu panic("Unsupported width!"); 4172690Sktlim@umich.edu } 4182690Sktlim@umich.edu 4192702Sktlim@umich.edu /** Records an fp register being set to a value. */ 4202690Sktlim@umich.edu void setFloatReg(const StaticInst *si, int idx, FloatReg val) 4211060SN/A { 4222308SN/A instResult.fp = val; 4232308SN/A } 4241060SN/A 4252702Sktlim@umich.edu /** Records an fp register being set to an integer value. */ 4262690Sktlim@umich.edu void setFloatRegBits(const StaticInst *si, int idx, uint64_t val, int width) 4272308SN/A { 4282690Sktlim@umich.edu instResult.integer = val; 4292308SN/A } 4301060SN/A 4312702Sktlim@umich.edu /** Records an fp register being set to an integer value. */ 4322690Sktlim@umich.edu void setFloatRegBits(const StaticInst *si, int idx, uint64_t val) 4332308SN/A { 4342308SN/A instResult.integer = val; 4351060SN/A } 4361060SN/A 4372190SN/A /** Records that one of the source registers is ready. */ 4382292SN/A void markSrcRegReady(); 4392190SN/A 4402331SN/A /** Marks a specific register as ready. */ 4412292SN/A void markSrcRegReady(RegIndex src_idx); 4422190SN/A 4431684SN/A /** Returns if a source register is ready. */ 4441464SN/A bool isReadySrcRegIdx(int idx) const 4451464SN/A { 4461464SN/A return this->_readySrcRegIdx[idx]; 4471464SN/A } 4481464SN/A 4491684SN/A /** Sets this instruction as completed. */ 4502731Sktlim@umich.edu void setCompleted() { status.set(Completed); } 4511464SN/A 4522292SN/A /** Returns whether or not this instruction is completed. */ 4532731Sktlim@umich.edu bool isCompleted() const { return status[Completed]; } 4541464SN/A 4552731Sktlim@umich.edu /** Marks the result as ready. */ 4562731Sktlim@umich.edu void setResultReady() { status.set(ResultReady); } 4572308SN/A 4582731Sktlim@umich.edu /** Returns whether or not the result is ready. */ 4592731Sktlim@umich.edu bool isResultReady() const { return status[ResultReady]; } 4602308SN/A 4611060SN/A /** Sets this instruction as ready to issue. */ 4622731Sktlim@umich.edu void setCanIssue() { status.set(CanIssue); } 4631060SN/A 4641060SN/A /** Returns whether or not this instruction is ready to issue. */ 4652731Sktlim@umich.edu bool readyToIssue() const { return status[CanIssue]; } 4661060SN/A 4671060SN/A /** Sets this instruction as issued from the IQ. */ 4682731Sktlim@umich.edu void setIssued() { status.set(Issued); } 4691060SN/A 4701060SN/A /** Returns whether or not this instruction has issued. */ 4712731Sktlim@umich.edu bool isIssued() const { return status[Issued]; } 4721060SN/A 4731060SN/A /** Sets this instruction as executed. */ 4742731Sktlim@umich.edu void setExecuted() { status.set(Executed); } 4751060SN/A 4761060SN/A /** Returns whether or not this instruction has executed. */ 4772731Sktlim@umich.edu bool isExecuted() const { return status[Executed]; } 4781060SN/A 4791060SN/A /** Sets this instruction as ready to commit. */ 4802731Sktlim@umich.edu void setCanCommit() { status.set(CanCommit); } 4811060SN/A 4821061SN/A /** Clears this instruction as being ready to commit. */ 4832731Sktlim@umich.edu void clearCanCommit() { status.reset(CanCommit); } 4841061SN/A 4851060SN/A /** Returns whether or not this instruction is ready to commit. */ 4862731Sktlim@umich.edu bool readyToCommit() const { return status[CanCommit]; } 4872731Sktlim@umich.edu 4882731Sktlim@umich.edu void setAtCommit() { status.set(AtCommit); } 4892731Sktlim@umich.edu 4902731Sktlim@umich.edu bool isAtCommit() { return status[AtCommit]; } 4911060SN/A 4922292SN/A /** Sets this instruction as committed. */ 4932731Sktlim@umich.edu void setCommitted() { status.set(Committed); } 4942292SN/A 4952292SN/A /** Returns whether or not this instruction is committed. */ 4962731Sktlim@umich.edu bool isCommitted() const { return status[Committed]; } 4972292SN/A 4981060SN/A /** Sets this instruction as squashed. */ 4992731Sktlim@umich.edu void setSquashed() { status.set(Squashed); } 5001060SN/A 5011060SN/A /** Returns whether or not this instruction is squashed. */ 5022731Sktlim@umich.edu bool isSquashed() const { return status[Squashed]; } 5031060SN/A 5042292SN/A //Instruction Queue Entry 5052292SN/A //----------------------- 5062292SN/A /** Sets this instruction as a entry the IQ. */ 5072731Sktlim@umich.edu void setInIQ() { status.set(IqEntry); } 5082292SN/A 5092292SN/A /** Sets this instruction as a entry the IQ. */ 5102731Sktlim@umich.edu void clearInIQ() { status.reset(IqEntry); } 5112731Sktlim@umich.edu 5122731Sktlim@umich.edu /** Returns whether or not this instruction has issued. */ 5132731Sktlim@umich.edu bool isInIQ() const { return status[IqEntry]; } 5142292SN/A 5151060SN/A /** Sets this instruction as squashed in the IQ. */ 5162731Sktlim@umich.edu void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);} 5171060SN/A 5181060SN/A /** Returns whether or not this instruction is squashed in the IQ. */ 5192731Sktlim@umich.edu bool isSquashedInIQ() const { return status[SquashedInIQ]; } 5202292SN/A 5212292SN/A 5222292SN/A //Load / Store Queue Functions 5232292SN/A //----------------------- 5242292SN/A /** Sets this instruction as a entry the LSQ. */ 5252731Sktlim@umich.edu void setInLSQ() { status.set(LsqEntry); } 5262292SN/A 5272292SN/A /** Sets this instruction as a entry the LSQ. */ 5282731Sktlim@umich.edu void removeInLSQ() { status.reset(LsqEntry); } 5292731Sktlim@umich.edu 5302731Sktlim@umich.edu /** Returns whether or not this instruction is in the LSQ. */ 5312731Sktlim@umich.edu bool isInLSQ() const { return status[LsqEntry]; } 5322292SN/A 5332292SN/A /** Sets this instruction as squashed in the LSQ. */ 5342731Sktlim@umich.edu void setSquashedInLSQ() { status.set(SquashedInLSQ);} 5352292SN/A 5362292SN/A /** Returns whether or not this instruction is squashed in the LSQ. */ 5372731Sktlim@umich.edu bool isSquashedInLSQ() const { return status[SquashedInLSQ]; } 5382292SN/A 5392292SN/A 5402292SN/A //Reorder Buffer Functions 5412292SN/A //----------------------- 5422292SN/A /** Sets this instruction as a entry the ROB. */ 5432731Sktlim@umich.edu void setInROB() { status.set(RobEntry); } 5442292SN/A 5452292SN/A /** Sets this instruction as a entry the ROB. */ 5462731Sktlim@umich.edu void clearInROB() { status.reset(RobEntry); } 5472731Sktlim@umich.edu 5482731Sktlim@umich.edu /** Returns whether or not this instruction is in the ROB. */ 5492731Sktlim@umich.edu bool isInROB() const { return status[RobEntry]; } 5502292SN/A 5512292SN/A /** Sets this instruction as squashed in the ROB. */ 5522731Sktlim@umich.edu void setSquashedInROB() { status.set(SquashedInROB); } 5532292SN/A 5542292SN/A /** Returns whether or not this instruction is squashed in the ROB. */ 5552731Sktlim@umich.edu bool isSquashedInROB() const { return status[SquashedInROB]; } 5562292SN/A 5571060SN/A /** Read the PC of this instruction. */ 5581464SN/A const Addr readPC() const { return PC; } 5591060SN/A 5601060SN/A /** Set the next PC of this instruction (its actual target). */ 5612308SN/A void setNextPC(uint64_t val) 5622308SN/A { 5632308SN/A nextPC = val; 5642308SN/A } 5652190SN/A 5662935Sksewell@umich.edu /** Set the next NPC of this instruction (the target in Mips or Sparc).*/ 5672935Sksewell@umich.edu void setNextNPC(uint64_t val) 5682935Sksewell@umich.edu { 5692935Sksewell@umich.edu nextNPC = val; 5702935Sksewell@umich.edu } 5712935Sksewell@umich.edu 5722702Sktlim@umich.edu /** Sets the ASID. */ 5732292SN/A void setASID(short addr_space_id) { asid = addr_space_id; } 5742292SN/A 5752702Sktlim@umich.edu /** Sets the thread id. */ 5762702Sktlim@umich.edu void setTid(unsigned tid) { threadNumber = tid; } 5772292SN/A 5782731Sktlim@umich.edu /** Sets the pointer to the thread state. */ 5792702Sktlim@umich.edu void setThreadState(ImplState *state) { thread = state; } 5801060SN/A 5812731Sktlim@umich.edu /** Returns the thread context. */ 5822680Sktlim@umich.edu ThreadContext *tcBase() { return thread->getTC(); } 5831464SN/A 5841464SN/A private: 5851684SN/A /** Instruction effective address. 5861684SN/A * @todo: Consider if this is necessary or not. 5871684SN/A */ 5881464SN/A Addr instEffAddr; 5892292SN/A 5901684SN/A /** Whether or not the effective address calculation is completed. 5911684SN/A * @todo: Consider if this is necessary or not. 5921684SN/A */ 5931464SN/A bool eaCalcDone; 5941464SN/A 5951464SN/A public: 5961684SN/A /** Sets the effective address. */ 5971464SN/A void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; } 5981684SN/A 5991684SN/A /** Returns the effective address. */ 6001464SN/A const Addr &getEA() const { return instEffAddr; } 6011684SN/A 6021684SN/A /** Returns whether or not the eff. addr. calculation has been completed. */ 6031464SN/A bool doneEACalc() { return eaCalcDone; } 6041684SN/A 6051684SN/A /** Returns whether or not the eff. addr. source registers are ready. */ 6061464SN/A bool eaSrcsReady(); 6071681SN/A 6082292SN/A /** Whether or not the memory operation is done. */ 6092292SN/A bool memOpDone; 6102292SN/A 6111681SN/A public: 6121684SN/A /** Load queue index. */ 6131681SN/A int16_t lqIdx; 6141684SN/A 6151684SN/A /** Store queue index. */ 6161681SN/A int16_t sqIdx; 6172292SN/A 6182292SN/A /** Iterator pointing to this BaseDynInst in the list of all insts. */ 6192292SN/A ListIt instListIt; 6202292SN/A 6212292SN/A /** Returns iterator to this instruction in the list of all insts. */ 6222292SN/A ListIt &getInstListIt() { return instListIt; } 6232292SN/A 6242292SN/A /** Sets iterator for this instruction in the list of all insts. */ 6252292SN/A void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; } 6261060SN/A}; 6271060SN/A 6281060SN/Atemplate<class Impl> 6291060SN/Atemplate<class T> 6302132SN/Ainline Fault 6311060SN/ABaseDynInst<Impl>::read(Addr addr, T &data, unsigned flags) 6321060SN/A{ 6332695Sktlim@umich.edu // Sometimes reads will get retried, so they may come through here 6342695Sktlim@umich.edu // twice. 6352695Sktlim@umich.edu if (!req) { 6362695Sktlim@umich.edu req = new Request(); 6372695Sktlim@umich.edu req->setVirt(asid, addr, sizeof(T), flags, this->PC); 6382695Sktlim@umich.edu req->setThreadContext(thread->readCpuId(), threadNumber); 6392695Sktlim@umich.edu } else { 6402695Sktlim@umich.edu assert(addr == req->getVaddr()); 6412292SN/A } 6422292SN/A 6432669Sktlim@umich.edu if ((req->getVaddr() & (TheISA::VMPageSize - 1)) + req->getSize() > 6442292SN/A TheISA::VMPageSize) { 6452292SN/A return TheISA::genAlignmentFault(); 6462292SN/A } 6471060SN/A 6482690Sktlim@umich.edu fault = cpu->translateDataReadReq(req, thread); 6491060SN/A 6502678Sktlim@umich.edu if (fault == NoFault) { 6512678Sktlim@umich.edu effAddr = req->getVaddr(); 6522678Sktlim@umich.edu physEffAddr = req->getPaddr(); 6532678Sktlim@umich.edu memReqFlags = req->getFlags(); 6541060SN/A 6552690Sktlim@umich.edu#if 0 6562292SN/A if (cpu->system->memctrl->badaddr(physEffAddr)) { 6572292SN/A fault = TheISA::genMachineCheckFault(); 6582292SN/A data = (T)-1; 6592292SN/A this->setExecuted(); 6602292SN/A } else { 6612292SN/A fault = cpu->read(req, data, lqIdx); 6622292SN/A } 6632292SN/A#else 6641681SN/A fault = cpu->read(req, data, lqIdx); 6652632Sstever@eecs.umich.edu#endif 6661684SN/A } else { 6671060SN/A // Return a fixed value to keep simulation deterministic even 6681060SN/A // along misspeculated paths. 6691060SN/A data = (T)-1; 6702292SN/A 6712292SN/A // Commit will have to clean up whatever happened. Set this 6722292SN/A // instruction as executed. 6732292SN/A this->setExecuted(); 6741060SN/A } 6751060SN/A 6761060SN/A if (traceData) { 6771060SN/A traceData->setAddr(addr); 6781060SN/A traceData->setData(data); 6791060SN/A } 6801060SN/A 6811060SN/A return fault; 6821060SN/A} 6831060SN/A 6841060SN/Atemplate<class Impl> 6851060SN/Atemplate<class T> 6862132SN/Ainline Fault 6871060SN/ABaseDynInst<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res) 6881060SN/A{ 6891060SN/A if (traceData) { 6901060SN/A traceData->setAddr(addr); 6911060SN/A traceData->setData(data); 6921060SN/A } 6931060SN/A 6942695Sktlim@umich.edu assert(req == NULL); 6952695Sktlim@umich.edu 6962669Sktlim@umich.edu req = new Request(); 6972669Sktlim@umich.edu req->setVirt(asid, addr, sizeof(T), flags, this->PC); 6982683Sktlim@umich.edu req->setThreadContext(thread->readCpuId(), threadNumber); 6991060SN/A 7002669Sktlim@umich.edu if ((req->getVaddr() & (TheISA::VMPageSize - 1)) + req->getSize() > 7012292SN/A TheISA::VMPageSize) { 7022292SN/A return TheISA::genAlignmentFault(); 7032292SN/A } 7041060SN/A 7052690Sktlim@umich.edu fault = cpu->translateDataWriteReq(req, thread); 7061060SN/A 7072090SN/A if (fault == NoFault) { 7082678Sktlim@umich.edu effAddr = req->getVaddr(); 7092678Sktlim@umich.edu physEffAddr = req->getPaddr(); 7102678Sktlim@umich.edu memReqFlags = req->getFlags(); 7112690Sktlim@umich.edu#if 0 7122292SN/A if (cpu->system->memctrl->badaddr(physEffAddr)) { 7132292SN/A fault = TheISA::genMachineCheckFault(); 7142292SN/A } else { 7152292SN/A fault = cpu->write(req, data, sqIdx); 7162292SN/A } 7172292SN/A#else 7181681SN/A fault = cpu->write(req, data, sqIdx); 7192632Sstever@eecs.umich.edu#endif 7201060SN/A } 7211060SN/A 7221060SN/A if (res) { 7231060SN/A // always return some result to keep misspeculated paths 7241060SN/A // (which will ignore faults) deterministic 7252669Sktlim@umich.edu *res = (fault == NoFault) ? req->getScResult() : 0; 7261060SN/A } 7271060SN/A 7281060SN/A return fault; 7291060SN/A} 7301060SN/A 7311464SN/A#endif // __CPU_BASE_DYN_INST_HH__ 732