base_dyn_inst.hh revision 5714
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"
423770Sgblack@eecs.umich.edu#include "cpu/o3/comm.hh"
431464SN/A#include "cpu/exetrace.hh"
441464SN/A#include "cpu/inst_seq.hh"
452669Sktlim@umich.edu#include "cpu/op_class.hh"
461060SN/A#include "cpu/static_inst.hh"
472669Sktlim@umich.edu#include "mem/packet.hh"
482292SN/A#include "sim/system.hh"
491060SN/A
501060SN/A/**
511060SN/A * @file
521060SN/A * Defines a dynamic instruction context.
531060SN/A */
541060SN/A
551061SN/A// Forward declaration.
561061SN/Aclass StaticInstPtr;
571060SN/A
581060SN/Atemplate <class Impl>
591061SN/Aclass BaseDynInst : public FastAlloc, public RefCounted
601060SN/A{
611060SN/A  public:
621060SN/A    // Typedef for the CPU.
632733Sktlim@umich.edu    typedef typename Impl::CPUType ImplCPU;
642733Sktlim@umich.edu    typedef typename ImplCPU::ImplState ImplState;
651060SN/A
662292SN/A    // Logical register index type.
672107SN/A    typedef TheISA::RegIndex RegIndex;
682690Sktlim@umich.edu    // Integer register type.
692107SN/A    typedef TheISA::IntReg IntReg;
702690Sktlim@umich.edu    // Floating point register type.
712690Sktlim@umich.edu    typedef TheISA::FloatReg FloatReg;
721060SN/A
732292SN/A    // The DynInstPtr type.
742292SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
752292SN/A
762292SN/A    // The list of instructions iterator type.
772292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
782292SN/A
791060SN/A    enum {
805543Ssaidi@eecs.umich.edu        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        /// Max source regs
815543Ssaidi@eecs.umich.edu        MaxInstDestRegs = TheISA::MaxInstDestRegs,      /// Max dest regs
821060SN/A    };
831060SN/A
842292SN/A    /** The StaticInst used by this BaseDynInst. */
852107SN/A    StaticInstPtr staticInst;
861060SN/A
871060SN/A    ////////////////////////////////////////////
881060SN/A    //
891060SN/A    // INSTRUCTION EXECUTION
901060SN/A    //
911060SN/A    ////////////////////////////////////////////
922292SN/A    /** InstRecord that tracks this instructions. */
931060SN/A    Trace::InstRecord *traceData;
941060SN/A
955358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
965358Sgblack@eecs.umich.edu    {
975358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
985358Sgblack@eecs.umich.edu    }
995358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
1005358Sgblack@eecs.umich.edu    {
1015358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1025358Sgblack@eecs.umich.edu    }
1035358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
1045358Sgblack@eecs.umich.edu    {
1055358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1065358Sgblack@eecs.umich.edu    }
1075358Sgblack@eecs.umich.edu
1082292SN/A    /**
1092292SN/A     * Does a read to a given address.
1102292SN/A     * @param addr The address to read.
1112292SN/A     * @param data The read's data is written into this parameter.
1122292SN/A     * @param flags The request's flags.
1132292SN/A     * @return Returns any fault due to the read.
1142292SN/A     */
1151060SN/A    template <class T>
1162132SN/A    Fault read(Addr addr, T &data, unsigned flags);
1171060SN/A
1185177Sgblack@eecs.umich.edu    Fault translateDataReadAddr(Addr vaddr, Addr &paddr,
1195177Sgblack@eecs.umich.edu            int size, unsigned flags);
1205177Sgblack@eecs.umich.edu
1212292SN/A    /**
1222292SN/A     * Does a write to a given address.
1232292SN/A     * @param data The data to be written.
1242292SN/A     * @param addr The address to write to.
1252292SN/A     * @param flags The request's flags.
1262292SN/A     * @param res The result of the write (for load locked/store conditionals).
1272292SN/A     * @return Returns any fault due to the write.
1282292SN/A     */
1291060SN/A    template <class T>
1302132SN/A    Fault write(T data, Addr addr, unsigned flags,
1311060SN/A                        uint64_t *res);
1321060SN/A
1335177Sgblack@eecs.umich.edu    Fault translateDataWriteAddr(Addr vaddr, Addr &paddr,
1345177Sgblack@eecs.umich.edu            int size, unsigned flags);
1355177Sgblack@eecs.umich.edu
1361060SN/A    void prefetch(Addr addr, unsigned flags);
1371060SN/A    void writeHint(Addr addr, int size, unsigned flags);
1382132SN/A    Fault copySrcTranslate(Addr src);
1392132SN/A    Fault copy(Addr dest);
1401060SN/A
1411684SN/A    /** @todo: Consider making this private. */
1421060SN/A  public:
1431060SN/A    /** The sequence number of the instruction. */
1441060SN/A    InstSeqNum seqNum;
1451060SN/A
1462731Sktlim@umich.edu    enum Status {
1472731Sktlim@umich.edu        IqEntry,                 /// Instruction is in the IQ
1482731Sktlim@umich.edu        RobEntry,                /// Instruction is in the ROB
1492731Sktlim@umich.edu        LsqEntry,                /// Instruction is in the LSQ
1502731Sktlim@umich.edu        Completed,               /// Instruction has completed
1512731Sktlim@umich.edu        ResultReady,             /// Instruction has its result
1522731Sktlim@umich.edu        CanIssue,                /// Instruction can issue and execute
1532731Sktlim@umich.edu        Issued,                  /// Instruction has issued
1542731Sktlim@umich.edu        Executed,                /// Instruction has executed
1552731Sktlim@umich.edu        CanCommit,               /// Instruction can commit
1562731Sktlim@umich.edu        AtCommit,                /// Instruction has reached commit
1572731Sktlim@umich.edu        Committed,               /// Instruction has committed
1582731Sktlim@umich.edu        Squashed,                /// Instruction is squashed
1592731Sktlim@umich.edu        SquashedInIQ,            /// Instruction is squashed in the IQ
1602731Sktlim@umich.edu        SquashedInLSQ,           /// Instruction is squashed in the LSQ
1612731Sktlim@umich.edu        SquashedInROB,           /// Instruction is squashed in the ROB
1622731Sktlim@umich.edu        RecoverInst,             /// Is a recover instruction
1632731Sktlim@umich.edu        BlockingInst,            /// Is a blocking instruction
1642731Sktlim@umich.edu        ThreadsyncWait,          /// Is a thread synchronization instruction
1652731Sktlim@umich.edu        SerializeBefore,         /// Needs to serialize on
1662731Sktlim@umich.edu                                 /// instructions ahead of it
1672731Sktlim@umich.edu        SerializeAfter,          /// Needs to serialize instructions behind it
1682731Sktlim@umich.edu        SerializeHandled,        /// Serialization has been handled
1692731Sktlim@umich.edu        NumStatus
1702731Sktlim@umich.edu    };
1712292SN/A
1722731Sktlim@umich.edu    /** The status of this BaseDynInst.  Several bits can be set. */
1732731Sktlim@umich.edu    std::bitset<NumStatus> status;
1741060SN/A
1751060SN/A    /** The thread this instruction is from. */
1761060SN/A    short threadNumber;
1771060SN/A
1781060SN/A    /** data address space ID, for loads & stores. */
1791060SN/A    short asid;
1801060SN/A
1812292SN/A    /** How many source registers are ready. */
1822292SN/A    unsigned readyRegs;
1832292SN/A
1842733Sktlim@umich.edu    /** Pointer to the Impl's CPU object. */
1852733Sktlim@umich.edu    ImplCPU *cpu;
1861060SN/A
1872680Sktlim@umich.edu    /** Pointer to the thread state. */
1882292SN/A    ImplState *thread;
1891060SN/A
1901060SN/A    /** The kind of fault this instruction has generated. */
1912132SN/A    Fault fault;
1921060SN/A
1932702Sktlim@umich.edu    /** Pointer to the data for the memory access. */
1942669Sktlim@umich.edu    uint8_t *memData;
1952292SN/A
1961060SN/A    /** The effective virtual address (lds & stores only). */
1971060SN/A    Addr effAddr;
1981060SN/A
1994032Sktlim@umich.edu    /** Is the effective virtual address valid. */
2004032Sktlim@umich.edu    bool effAddrValid;
2014032Sktlim@umich.edu
2021060SN/A    /** The effective physical address. */
2031060SN/A    Addr physEffAddr;
2041060SN/A
2051060SN/A    /** Effective virtual address for a copy source. */
2061060SN/A    Addr copySrcEffAddr;
2071060SN/A
2081060SN/A    /** Effective physical address for a copy source. */
2091060SN/A    Addr copySrcPhysEffAddr;
2101060SN/A
2111060SN/A    /** The memory request flags (from translation). */
2121060SN/A    unsigned memReqFlags;
2131060SN/A
2141464SN/A    union Result {
2151464SN/A        uint64_t integer;
2162356SN/A//        float fp;
2171464SN/A        double dbl;
2181464SN/A    };
2191060SN/A
2201464SN/A    /** The result of the instruction; assumes for now that there's only one
2211464SN/A     *  destination register.
2221464SN/A     */
2231464SN/A    Result instResult;
2241060SN/A
2253326Sktlim@umich.edu    /** Records changes to result? */
2263326Sktlim@umich.edu    bool recordResult;
2273326Sktlim@umich.edu
2281060SN/A    /** PC of this instruction. */
2291060SN/A    Addr PC;
2301060SN/A
2314636Sgblack@eecs.umich.edu    /** Micro PC of this instruction. */
2324636Sgblack@eecs.umich.edu    Addr microPC;
2334636Sgblack@eecs.umich.edu
2343965Sgblack@eecs.umich.edu  protected:
2351060SN/A    /** Next non-speculative PC.  It is not filled in at fetch, but rather
2361060SN/A     *  once the target of the branch is truly known (either decode or
2371060SN/A     *  execute).
2381060SN/A     */
2391060SN/A    Addr nextPC;
2401060SN/A
2412935Sksewell@umich.edu    /** Next non-speculative NPC. Target PC for Mips or Sparc. */
2422935Sksewell@umich.edu    Addr nextNPC;
2432935Sksewell@umich.edu
2444636Sgblack@eecs.umich.edu    /** Next non-speculative micro PC. */
2454636Sgblack@eecs.umich.edu    Addr nextMicroPC;
2464636Sgblack@eecs.umich.edu
2471060SN/A    /** Predicted next PC. */
2481060SN/A    Addr predPC;
2491060SN/A
2503794Sgblack@eecs.umich.edu    /** Predicted next NPC. */
2513794Sgblack@eecs.umich.edu    Addr predNPC;
2523794Sgblack@eecs.umich.edu
2534636Sgblack@eecs.umich.edu    /** Predicted next microPC */
2544636Sgblack@eecs.umich.edu    Addr predMicroPC;
2554636Sgblack@eecs.umich.edu
2563794Sgblack@eecs.umich.edu    /** If this is a branch that was predicted taken */
2573794Sgblack@eecs.umich.edu    bool predTaken;
2583794Sgblack@eecs.umich.edu
2593965Sgblack@eecs.umich.edu  public:
2603965Sgblack@eecs.umich.edu
2611060SN/A    /** Count of total number of dynamic instructions. */
2621060SN/A    static int instcount;
2631060SN/A
2642292SN/A#ifdef DEBUG
2652292SN/A    void dumpSNList();
2662292SN/A#endif
2672292SN/A
2682292SN/A    /** Whether or not the source register is ready.
2692292SN/A     *  @todo: Not sure this should be here vs the derived class.
2701060SN/A     */
2711060SN/A    bool _readySrcRegIdx[MaxInstSrcRegs];
2721060SN/A
2733770Sgblack@eecs.umich.edu  protected:
2743770Sgblack@eecs.umich.edu    /** Flattened register index of the destination registers of this
2753770Sgblack@eecs.umich.edu     *  instruction.
2763770Sgblack@eecs.umich.edu     */
2773770Sgblack@eecs.umich.edu    TheISA::RegIndex _flatDestRegIdx[TheISA::MaxInstDestRegs];
2783770Sgblack@eecs.umich.edu
2793770Sgblack@eecs.umich.edu    /** Flattened register index of the source registers of this
2803770Sgblack@eecs.umich.edu     *  instruction.
2813770Sgblack@eecs.umich.edu     */
2823770Sgblack@eecs.umich.edu    TheISA::RegIndex _flatSrcRegIdx[TheISA::MaxInstSrcRegs];
2833770Sgblack@eecs.umich.edu
2843770Sgblack@eecs.umich.edu    /** Physical register index of the destination registers of this
2853770Sgblack@eecs.umich.edu     *  instruction.
2863770Sgblack@eecs.umich.edu     */
2873770Sgblack@eecs.umich.edu    PhysRegIndex _destRegIdx[TheISA::MaxInstDestRegs];
2883770Sgblack@eecs.umich.edu
2893770Sgblack@eecs.umich.edu    /** Physical register index of the source registers of this
2903770Sgblack@eecs.umich.edu     *  instruction.
2913770Sgblack@eecs.umich.edu     */
2923770Sgblack@eecs.umich.edu    PhysRegIndex _srcRegIdx[TheISA::MaxInstSrcRegs];
2933770Sgblack@eecs.umich.edu
2943770Sgblack@eecs.umich.edu    /** Physical register index of the previous producers of the
2953770Sgblack@eecs.umich.edu     *  architected destinations.
2963770Sgblack@eecs.umich.edu     */
2973770Sgblack@eecs.umich.edu    PhysRegIndex _prevDestRegIdx[TheISA::MaxInstDestRegs];
2983770Sgblack@eecs.umich.edu
2991060SN/A  public:
3003770Sgblack@eecs.umich.edu
3013770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th destination
3023770Sgblack@eecs.umich.edu     *  register.
3033770Sgblack@eecs.umich.edu     */
3043770Sgblack@eecs.umich.edu    PhysRegIndex renamedDestRegIdx(int idx) const
3053770Sgblack@eecs.umich.edu    {
3063770Sgblack@eecs.umich.edu        return _destRegIdx[idx];
3073770Sgblack@eecs.umich.edu    }
3083770Sgblack@eecs.umich.edu
3093770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th source register. */
3103770Sgblack@eecs.umich.edu    PhysRegIndex renamedSrcRegIdx(int idx) const
3113770Sgblack@eecs.umich.edu    {
3123770Sgblack@eecs.umich.edu        return _srcRegIdx[idx];
3133770Sgblack@eecs.umich.edu    }
3143770Sgblack@eecs.umich.edu
3153770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th destination
3163770Sgblack@eecs.umich.edu     *  register.
3173770Sgblack@eecs.umich.edu     */
3183770Sgblack@eecs.umich.edu    TheISA::RegIndex flattenedDestRegIdx(int idx) const
3193770Sgblack@eecs.umich.edu    {
3203770Sgblack@eecs.umich.edu        return _flatDestRegIdx[idx];
3213770Sgblack@eecs.umich.edu    }
3223770Sgblack@eecs.umich.edu
3233770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th source register */
3243770Sgblack@eecs.umich.edu    TheISA::RegIndex flattenedSrcRegIdx(int idx) const
3253770Sgblack@eecs.umich.edu    {
3263770Sgblack@eecs.umich.edu        return _flatSrcRegIdx[idx];
3273770Sgblack@eecs.umich.edu    }
3283770Sgblack@eecs.umich.edu
3293770Sgblack@eecs.umich.edu    /** Returns the physical register index of the previous physical register
3303770Sgblack@eecs.umich.edu     *  that remapped to the same logical register index.
3313770Sgblack@eecs.umich.edu     */
3323770Sgblack@eecs.umich.edu    PhysRegIndex prevDestRegIdx(int idx) const
3333770Sgblack@eecs.umich.edu    {
3343770Sgblack@eecs.umich.edu        return _prevDestRegIdx[idx];
3353770Sgblack@eecs.umich.edu    }
3363770Sgblack@eecs.umich.edu
3373770Sgblack@eecs.umich.edu    /** Renames a destination register to a physical register.  Also records
3383770Sgblack@eecs.umich.edu     *  the previous physical register that the logical register mapped to.
3393770Sgblack@eecs.umich.edu     */
3403770Sgblack@eecs.umich.edu    void renameDestReg(int idx,
3413770Sgblack@eecs.umich.edu                       PhysRegIndex renamed_dest,
3423770Sgblack@eecs.umich.edu                       PhysRegIndex previous_rename)
3433770Sgblack@eecs.umich.edu    {
3443770Sgblack@eecs.umich.edu        _destRegIdx[idx] = renamed_dest;
3453770Sgblack@eecs.umich.edu        _prevDestRegIdx[idx] = previous_rename;
3463770Sgblack@eecs.umich.edu    }
3473770Sgblack@eecs.umich.edu
3483770Sgblack@eecs.umich.edu    /** Renames a source logical register to the physical register which
3493770Sgblack@eecs.umich.edu     *  has/will produce that logical register's result.
3503770Sgblack@eecs.umich.edu     *  @todo: add in whether or not the source register is ready.
3513770Sgblack@eecs.umich.edu     */
3523770Sgblack@eecs.umich.edu    void renameSrcReg(int idx, PhysRegIndex renamed_src)
3533770Sgblack@eecs.umich.edu    {
3543770Sgblack@eecs.umich.edu        _srcRegIdx[idx] = renamed_src;
3553770Sgblack@eecs.umich.edu    }
3563770Sgblack@eecs.umich.edu
3573770Sgblack@eecs.umich.edu    /** Flattens a source architectural register index into a logical index.
3583770Sgblack@eecs.umich.edu     */
3593770Sgblack@eecs.umich.edu    void flattenSrcReg(int idx, TheISA::RegIndex flattened_src)
3603770Sgblack@eecs.umich.edu    {
3613770Sgblack@eecs.umich.edu        _flatSrcRegIdx[idx] = flattened_src;
3623770Sgblack@eecs.umich.edu    }
3633770Sgblack@eecs.umich.edu
3643770Sgblack@eecs.umich.edu    /** Flattens a destination architectural register index into a logical
3653770Sgblack@eecs.umich.edu     * index.
3663770Sgblack@eecs.umich.edu     */
3673770Sgblack@eecs.umich.edu    void flattenDestReg(int idx, TheISA::RegIndex flattened_dest)
3683770Sgblack@eecs.umich.edu    {
3693770Sgblack@eecs.umich.edu        _flatDestRegIdx[idx] = flattened_dest;
3703770Sgblack@eecs.umich.edu    }
3714636Sgblack@eecs.umich.edu    /** BaseDynInst constructor given a binary instruction.
3724636Sgblack@eecs.umich.edu     *  @param staticInst A StaticInstPtr to the underlying instruction.
3734636Sgblack@eecs.umich.edu     *  @param PC The PC of the instruction.
3744636Sgblack@eecs.umich.edu     *  @param pred_PC The predicted next PC.
3754636Sgblack@eecs.umich.edu     *  @param pred_NPC The predicted next NPC.
3764636Sgblack@eecs.umich.edu     *  @param seq_num The sequence number of the instruction.
3774636Sgblack@eecs.umich.edu     *  @param cpu Pointer to the instruction's CPU.
3784636Sgblack@eecs.umich.edu     */
3794636Sgblack@eecs.umich.edu    BaseDynInst(StaticInstPtr staticInst, Addr PC, Addr NPC, Addr microPC,
3804636Sgblack@eecs.umich.edu            Addr pred_PC, Addr pred_NPC, Addr pred_MicroPC,
3814636Sgblack@eecs.umich.edu            InstSeqNum seq_num, ImplCPU *cpu);
3823770Sgblack@eecs.umich.edu
3832292SN/A    /** BaseDynInst constructor given a binary instruction.
3842292SN/A     *  @param inst The binary instruction.
3852292SN/A     *  @param PC The PC of the instruction.
3862292SN/A     *  @param pred_PC The predicted next PC.
3873794Sgblack@eecs.umich.edu     *  @param pred_NPC The predicted next NPC.
3882292SN/A     *  @param seq_num The sequence number of the instruction.
3892292SN/A     *  @param cpu Pointer to the instruction's CPU.
3902292SN/A     */
3914636Sgblack@eecs.umich.edu    BaseDynInst(TheISA::ExtMachInst inst, Addr PC, Addr NPC, Addr microPC,
3924636Sgblack@eecs.umich.edu            Addr pred_PC, Addr pred_NPC, Addr pred_MicroPC,
3933770Sgblack@eecs.umich.edu            InstSeqNum seq_num, ImplCPU *cpu);
3941060SN/A
3952292SN/A    /** BaseDynInst constructor given a StaticInst pointer.
3962292SN/A     *  @param _staticInst The StaticInst for this BaseDynInst.
3972292SN/A     */
3982107SN/A    BaseDynInst(StaticInstPtr &_staticInst);
3991060SN/A
4001060SN/A    /** BaseDynInst destructor. */
4011060SN/A    ~BaseDynInst();
4021060SN/A
4031464SN/A  private:
4041684SN/A    /** Function to initialize variables in the constructors. */
4051464SN/A    void initVars();
4061060SN/A
4071464SN/A  public:
4081060SN/A    /** Dumps out contents of this BaseDynInst. */
4091060SN/A    void dump();
4101060SN/A
4111060SN/A    /** Dumps out contents of this BaseDynInst into given string. */
4121060SN/A    void dump(std::string &outstring);
4131060SN/A
4143326Sktlim@umich.edu    /** Read this CPU's ID. */
4155712Shsul@eecs.umich.edu    int cpuId() { return cpu->cpuId(); }
4163326Sktlim@umich.edu
4175714Shsul@eecs.umich.edu    /** Read this context's system-wide ID **/
4185714Shsul@eecs.umich.edu    int contextId() { return thread->contextId(); }
4195714Shsul@eecs.umich.edu
4201060SN/A    /** Returns the fault type. */
4212132SN/A    Fault getFault() { return fault; }
4221060SN/A
4231060SN/A    /** Checks whether or not this instruction has had its branch target
4241060SN/A     *  calculated yet.  For now it is not utilized and is hacked to be
4251060SN/A     *  always false.
4262292SN/A     *  @todo: Actually use this instruction.
4271060SN/A     */
4281060SN/A    bool doneTargCalc() { return false; }
4291060SN/A
4301684SN/A    /** Returns the next PC.  This could be the speculative next PC if it is
4311684SN/A     *  called prior to the actual branch target being calculated.
4321684SN/A     */
4331060SN/A    Addr readNextPC() { return nextPC; }
4341060SN/A
4352935Sksewell@umich.edu    /** Returns the next NPC.  This could be the speculative next NPC if it is
4362935Sksewell@umich.edu     *  called prior to the actual branch target being calculated.
4372935Sksewell@umich.edu     */
4383965Sgblack@eecs.umich.edu    Addr readNextNPC()
4393965Sgblack@eecs.umich.edu    {
4403965Sgblack@eecs.umich.edu#if ISA_HAS_DELAY_SLOT
4413965Sgblack@eecs.umich.edu        return nextNPC;
4423965Sgblack@eecs.umich.edu#else
4433965Sgblack@eecs.umich.edu        return nextPC + sizeof(TheISA::MachInst);
4443965Sgblack@eecs.umich.edu#endif
4453965Sgblack@eecs.umich.edu    }
4462935Sksewell@umich.edu
4474636Sgblack@eecs.umich.edu    Addr readNextMicroPC()
4484636Sgblack@eecs.umich.edu    {
4494636Sgblack@eecs.umich.edu        return nextMicroPC;
4504636Sgblack@eecs.umich.edu    }
4514636Sgblack@eecs.umich.edu
4521060SN/A    /** Set the predicted target of this current instruction. */
4534636Sgblack@eecs.umich.edu    void setPredTarg(Addr predicted_PC, Addr predicted_NPC,
4544636Sgblack@eecs.umich.edu            Addr predicted_MicroPC)
4553794Sgblack@eecs.umich.edu    {
4563794Sgblack@eecs.umich.edu        predPC = predicted_PC;
4573794Sgblack@eecs.umich.edu        predNPC = predicted_NPC;
4584636Sgblack@eecs.umich.edu        predMicroPC = predicted_MicroPC;
4593794Sgblack@eecs.umich.edu    }
4601060SN/A
4613794Sgblack@eecs.umich.edu    /** Returns the predicted PC immediately after the branch. */
4623794Sgblack@eecs.umich.edu    Addr readPredPC() { return predPC; }
4633794Sgblack@eecs.umich.edu
4643794Sgblack@eecs.umich.edu    /** Returns the predicted PC two instructions after the branch */
4653794Sgblack@eecs.umich.edu    Addr readPredNPC() { return predNPC; }
4661060SN/A
4674636Sgblack@eecs.umich.edu    /** Returns the predicted micro PC after the branch */
4684636Sgblack@eecs.umich.edu    Addr readPredMicroPC() { return predMicroPC; }
4694636Sgblack@eecs.umich.edu
4701060SN/A    /** Returns whether the instruction was predicted taken or not. */
4713794Sgblack@eecs.umich.edu    bool readPredTaken()
4723794Sgblack@eecs.umich.edu    {
4733794Sgblack@eecs.umich.edu        return predTaken;
4743794Sgblack@eecs.umich.edu    }
4753794Sgblack@eecs.umich.edu
4763794Sgblack@eecs.umich.edu    void setPredTaken(bool predicted_taken)
4773794Sgblack@eecs.umich.edu    {
4783794Sgblack@eecs.umich.edu        predTaken = predicted_taken;
4793794Sgblack@eecs.umich.edu    }
4801060SN/A
4811060SN/A    /** Returns whether the instruction mispredicted. */
4822935Sksewell@umich.edu    bool mispredicted()
4833794Sgblack@eecs.umich.edu    {
4843965Sgblack@eecs.umich.edu        return readPredPC() != readNextPC() ||
4854636Sgblack@eecs.umich.edu            readPredNPC() != readNextNPC() ||
4864636Sgblack@eecs.umich.edu            readPredMicroPC() != readNextMicroPC();
4873794Sgblack@eecs.umich.edu    }
4883794Sgblack@eecs.umich.edu
4891060SN/A    //
4901060SN/A    //  Instruction types.  Forward checks to StaticInst object.
4911060SN/A    //
4925543Ssaidi@eecs.umich.edu    bool isNop()          const { return staticInst->isNop(); }
4935543Ssaidi@eecs.umich.edu    bool isMemRef()       const { return staticInst->isMemRef(); }
4945543Ssaidi@eecs.umich.edu    bool isLoad()         const { return staticInst->isLoad(); }
4955543Ssaidi@eecs.umich.edu    bool isStore()        const { return staticInst->isStore(); }
4962336SN/A    bool isStoreConditional() const
4972336SN/A    { return staticInst->isStoreConditional(); }
4981060SN/A    bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
4991060SN/A    bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
5001060SN/A    bool isCopy()         const { return staticInst->isCopy(); }
5015543Ssaidi@eecs.umich.edu    bool isInteger()      const { return staticInst->isInteger(); }
5025543Ssaidi@eecs.umich.edu    bool isFloating()     const { return staticInst->isFloating(); }
5035543Ssaidi@eecs.umich.edu    bool isControl()      const { return staticInst->isControl(); }
5045543Ssaidi@eecs.umich.edu    bool isCall()         const { return staticInst->isCall(); }
5055543Ssaidi@eecs.umich.edu    bool isReturn()       const { return staticInst->isReturn(); }
5065543Ssaidi@eecs.umich.edu    bool isDirectCtrl()   const { return staticInst->isDirectCtrl(); }
5071060SN/A    bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
5085543Ssaidi@eecs.umich.edu    bool isCondCtrl()     const { return staticInst->isCondCtrl(); }
5095543Ssaidi@eecs.umich.edu    bool isUncondCtrl()   const { return staticInst->isUncondCtrl(); }
5102935Sksewell@umich.edu    bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
5111060SN/A    bool isThreadSync()   const { return staticInst->isThreadSync(); }
5121060SN/A    bool isSerializing()  const { return staticInst->isSerializing(); }
5132292SN/A    bool isSerializeBefore() const
5142731Sktlim@umich.edu    { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
5152292SN/A    bool isSerializeAfter() const
5162731Sktlim@umich.edu    { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
5171060SN/A    bool isMemBarrier()   const { return staticInst->isMemBarrier(); }
5181060SN/A    bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
5191060SN/A    bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
5202292SN/A    bool isQuiesce() const { return staticInst->isQuiesce(); }
5212336SN/A    bool isIprAccess() const { return staticInst->isIprAccess(); }
5222308SN/A    bool isUnverifiable() const { return staticInst->isUnverifiable(); }
5234828Sgblack@eecs.umich.edu    bool isSyscall() const { return staticInst->isSyscall(); }
5244654Sgblack@eecs.umich.edu    bool isMacroop() const { return staticInst->isMacroop(); }
5254654Sgblack@eecs.umich.edu    bool isMicroop() const { return staticInst->isMicroop(); }
5264636Sgblack@eecs.umich.edu    bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
5274654Sgblack@eecs.umich.edu    bool isLastMicroop() const { return staticInst->isLastMicroop(); }
5284654Sgblack@eecs.umich.edu    bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
5294636Sgblack@eecs.umich.edu    bool isMicroBranch() const { return staticInst->isMicroBranch(); }
5302292SN/A
5312292SN/A    /** Temporarily sets this instruction as a serialize before instruction. */
5322731Sktlim@umich.edu    void setSerializeBefore() { status.set(SerializeBefore); }
5332292SN/A
5342292SN/A    /** Clears the serializeBefore part of this instruction. */
5352731Sktlim@umich.edu    void clearSerializeBefore() { status.reset(SerializeBefore); }
5362292SN/A
5372292SN/A    /** Checks if this serializeBefore is only temporarily set. */
5382731Sktlim@umich.edu    bool isTempSerializeBefore() { return status[SerializeBefore]; }
5392292SN/A
5402292SN/A    /** Temporarily sets this instruction as a serialize after instruction. */
5412731Sktlim@umich.edu    void setSerializeAfter() { status.set(SerializeAfter); }
5422292SN/A
5432292SN/A    /** Clears the serializeAfter part of this instruction.*/
5442731Sktlim@umich.edu    void clearSerializeAfter() { status.reset(SerializeAfter); }
5452292SN/A
5462292SN/A    /** Checks if this serializeAfter is only temporarily set. */
5472731Sktlim@umich.edu    bool isTempSerializeAfter() { return status[SerializeAfter]; }
5482292SN/A
5492731Sktlim@umich.edu    /** Sets the serialization part of this instruction as handled. */
5502731Sktlim@umich.edu    void setSerializeHandled() { status.set(SerializeHandled); }
5512292SN/A
5522292SN/A    /** Checks if the serialization part of this instruction has been
5532292SN/A     *  handled.  This does not apply to the temporary serializing
5542292SN/A     *  state; it only applies to this instruction's own permanent
5552292SN/A     *  serializing state.
5562292SN/A     */
5572731Sktlim@umich.edu    bool isSerializeHandled() { return status[SerializeHandled]; }
5581060SN/A
5591464SN/A    /** Returns the opclass of this instruction. */
5601464SN/A    OpClass opClass() const { return staticInst->opClass(); }
5611464SN/A
5621464SN/A    /** Returns the branch target address. */
5631464SN/A    Addr branchTarget() const { return staticInst->branchTarget(PC); }
5641464SN/A
5652292SN/A    /** Returns the number of source registers. */
5665543Ssaidi@eecs.umich.edu    int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
5671684SN/A
5682292SN/A    /** Returns the number of destination registers. */
5691060SN/A    int8_t numDestRegs() const { return staticInst->numDestRegs(); }
5701060SN/A
5711060SN/A    // the following are used to track physical register usage
5721060SN/A    // for machines with separate int & FP reg files
5731060SN/A    int8_t numFPDestRegs()  const { return staticInst->numFPDestRegs(); }
5741060SN/A    int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
5751060SN/A
5761060SN/A    /** Returns the logical register index of the i'th destination register. */
5772292SN/A    RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
5781060SN/A
5791060SN/A    /** Returns the logical register index of the i'th source register. */
5802292SN/A    RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
5811060SN/A
5821684SN/A    /** Returns the result of an integer instruction. */
5831464SN/A    uint64_t readIntResult() { return instResult.integer; }
5841684SN/A
5851684SN/A    /** Returns the result of a floating point instruction. */
5862356SN/A    float readFloatResult() { return (float)instResult.dbl; }
5871684SN/A
5881684SN/A    /** Returns the result of a floating point (double) instruction. */
5891464SN/A    double readDoubleResult() { return instResult.dbl; }
5901060SN/A
5912702Sktlim@umich.edu    /** Records an integer register being set to a value. */
5923735Sstever@eecs.umich.edu    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
5931060SN/A    {
5943326Sktlim@umich.edu        if (recordResult)
5953326Sktlim@umich.edu            instResult.integer = val;
5961060SN/A    }
5971060SN/A
5982702Sktlim@umich.edu    /** Records an fp register being set to a value. */
5993735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
6003735Sstever@eecs.umich.edu                            int width)
6012690Sktlim@umich.edu    {
6023326Sktlim@umich.edu        if (recordResult) {
6033326Sktlim@umich.edu            if (width == 32)
6043326Sktlim@umich.edu                instResult.dbl = (double)val;
6053326Sktlim@umich.edu            else if (width == 64)
6063326Sktlim@umich.edu                instResult.dbl = val;
6073326Sktlim@umich.edu            else
6083326Sktlim@umich.edu                panic("Unsupported width!");
6093326Sktlim@umich.edu        }
6102690Sktlim@umich.edu    }
6112690Sktlim@umich.edu
6122702Sktlim@umich.edu    /** Records an fp register being set to a value. */
6133735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
6141060SN/A    {
6153326Sktlim@umich.edu        if (recordResult)
6163326Sktlim@umich.edu            instResult.dbl = (double)val;
6172308SN/A    }
6181060SN/A
6192702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
6203735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val,
6213735Sstever@eecs.umich.edu                                int width)
6222308SN/A    {
6233326Sktlim@umich.edu        if (recordResult)
6243326Sktlim@umich.edu            instResult.integer = val;
6252308SN/A    }
6261060SN/A
6272702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
6283735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val)
6292308SN/A    {
6303326Sktlim@umich.edu        if (recordResult)
6313326Sktlim@umich.edu            instResult.integer = val;
6321060SN/A    }
6331060SN/A
6342190SN/A    /** Records that one of the source registers is ready. */
6352292SN/A    void markSrcRegReady();
6362190SN/A
6372331SN/A    /** Marks a specific register as ready. */
6382292SN/A    void markSrcRegReady(RegIndex src_idx);
6392190SN/A
6401684SN/A    /** Returns if a source register is ready. */
6411464SN/A    bool isReadySrcRegIdx(int idx) const
6421464SN/A    {
6431464SN/A        return this->_readySrcRegIdx[idx];
6441464SN/A    }
6451464SN/A
6461684SN/A    /** Sets this instruction as completed. */
6472731Sktlim@umich.edu    void setCompleted() { status.set(Completed); }
6481464SN/A
6492292SN/A    /** Returns whether or not this instruction is completed. */
6502731Sktlim@umich.edu    bool isCompleted() const { return status[Completed]; }
6511464SN/A
6522731Sktlim@umich.edu    /** Marks the result as ready. */
6532731Sktlim@umich.edu    void setResultReady() { status.set(ResultReady); }
6542308SN/A
6552731Sktlim@umich.edu    /** Returns whether or not the result is ready. */
6562731Sktlim@umich.edu    bool isResultReady() const { return status[ResultReady]; }
6572308SN/A
6581060SN/A    /** Sets this instruction as ready to issue. */
6592731Sktlim@umich.edu    void setCanIssue() { status.set(CanIssue); }
6601060SN/A
6611060SN/A    /** Returns whether or not this instruction is ready to issue. */
6622731Sktlim@umich.edu    bool readyToIssue() const { return status[CanIssue]; }
6631060SN/A
6644032Sktlim@umich.edu    /** Clears this instruction being able to issue. */
6654032Sktlim@umich.edu    void clearCanIssue() { status.reset(CanIssue); }
6664032Sktlim@umich.edu
6671060SN/A    /** Sets this instruction as issued from the IQ. */
6682731Sktlim@umich.edu    void setIssued() { status.set(Issued); }
6691060SN/A
6701060SN/A    /** Returns whether or not this instruction has issued. */
6712731Sktlim@umich.edu    bool isIssued() const { return status[Issued]; }
6721060SN/A
6734032Sktlim@umich.edu    /** Clears this instruction as being issued. */
6744032Sktlim@umich.edu    void clearIssued() { status.reset(Issued); }
6754032Sktlim@umich.edu
6761060SN/A    /** Sets this instruction as executed. */
6772731Sktlim@umich.edu    void setExecuted() { status.set(Executed); }
6781060SN/A
6791060SN/A    /** Returns whether or not this instruction has executed. */
6802731Sktlim@umich.edu    bool isExecuted() const { return status[Executed]; }
6811060SN/A
6821060SN/A    /** Sets this instruction as ready to commit. */
6832731Sktlim@umich.edu    void setCanCommit() { status.set(CanCommit); }
6841060SN/A
6851061SN/A    /** Clears this instruction as being ready to commit. */
6862731Sktlim@umich.edu    void clearCanCommit() { status.reset(CanCommit); }
6871061SN/A
6881060SN/A    /** Returns whether or not this instruction is ready to commit. */
6892731Sktlim@umich.edu    bool readyToCommit() const { return status[CanCommit]; }
6902731Sktlim@umich.edu
6912731Sktlim@umich.edu    void setAtCommit() { status.set(AtCommit); }
6922731Sktlim@umich.edu
6932731Sktlim@umich.edu    bool isAtCommit() { return status[AtCommit]; }
6941060SN/A
6952292SN/A    /** Sets this instruction as committed. */
6962731Sktlim@umich.edu    void setCommitted() { status.set(Committed); }
6972292SN/A
6982292SN/A    /** Returns whether or not this instruction is committed. */
6992731Sktlim@umich.edu    bool isCommitted() const { return status[Committed]; }
7002292SN/A
7011060SN/A    /** Sets this instruction as squashed. */
7022731Sktlim@umich.edu    void setSquashed() { status.set(Squashed); }
7031060SN/A
7041060SN/A    /** Returns whether or not this instruction is squashed. */
7052731Sktlim@umich.edu    bool isSquashed() const { return status[Squashed]; }
7061060SN/A
7072292SN/A    //Instruction Queue Entry
7082292SN/A    //-----------------------
7092292SN/A    /** Sets this instruction as a entry the IQ. */
7102731Sktlim@umich.edu    void setInIQ() { status.set(IqEntry); }
7112292SN/A
7122292SN/A    /** Sets this instruction as a entry the IQ. */
7132731Sktlim@umich.edu    void clearInIQ() { status.reset(IqEntry); }
7142731Sktlim@umich.edu
7152731Sktlim@umich.edu    /** Returns whether or not this instruction has issued. */
7162731Sktlim@umich.edu    bool isInIQ() const { return status[IqEntry]; }
7172292SN/A
7181060SN/A    /** Sets this instruction as squashed in the IQ. */
7192731Sktlim@umich.edu    void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
7201060SN/A
7211060SN/A    /** Returns whether or not this instruction is squashed in the IQ. */
7222731Sktlim@umich.edu    bool isSquashedInIQ() const { return status[SquashedInIQ]; }
7232292SN/A
7242292SN/A
7252292SN/A    //Load / Store Queue Functions
7262292SN/A    //-----------------------
7272292SN/A    /** Sets this instruction as a entry the LSQ. */
7282731Sktlim@umich.edu    void setInLSQ() { status.set(LsqEntry); }
7292292SN/A
7302292SN/A    /** Sets this instruction as a entry the LSQ. */
7312731Sktlim@umich.edu    void removeInLSQ() { status.reset(LsqEntry); }
7322731Sktlim@umich.edu
7332731Sktlim@umich.edu    /** Returns whether or not this instruction is in the LSQ. */
7342731Sktlim@umich.edu    bool isInLSQ() const { return status[LsqEntry]; }
7352292SN/A
7362292SN/A    /** Sets this instruction as squashed in the LSQ. */
7372731Sktlim@umich.edu    void setSquashedInLSQ() { status.set(SquashedInLSQ);}
7382292SN/A
7392292SN/A    /** Returns whether or not this instruction is squashed in the LSQ. */
7402731Sktlim@umich.edu    bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
7412292SN/A
7422292SN/A
7432292SN/A    //Reorder Buffer Functions
7442292SN/A    //-----------------------
7452292SN/A    /** Sets this instruction as a entry the ROB. */
7462731Sktlim@umich.edu    void setInROB() { status.set(RobEntry); }
7472292SN/A
7482292SN/A    /** Sets this instruction as a entry the ROB. */
7492731Sktlim@umich.edu    void clearInROB() { status.reset(RobEntry); }
7502731Sktlim@umich.edu
7512731Sktlim@umich.edu    /** Returns whether or not this instruction is in the ROB. */
7522731Sktlim@umich.edu    bool isInROB() const { return status[RobEntry]; }
7532292SN/A
7542292SN/A    /** Sets this instruction as squashed in the ROB. */
7552731Sktlim@umich.edu    void setSquashedInROB() { status.set(SquashedInROB); }
7562292SN/A
7572292SN/A    /** Returns whether or not this instruction is squashed in the ROB. */
7582731Sktlim@umich.edu    bool isSquashedInROB() const { return status[SquashedInROB]; }
7592292SN/A
7601060SN/A    /** Read the PC of this instruction. */
7611464SN/A    const Addr readPC() const { return PC; }
7621060SN/A
7634636Sgblack@eecs.umich.edu    /**Read the micro PC of this instruction. */
7644636Sgblack@eecs.umich.edu    const Addr readMicroPC() const { return microPC; }
7654636Sgblack@eecs.umich.edu
7661060SN/A    /** Set the next PC of this instruction (its actual target). */
7674636Sgblack@eecs.umich.edu    void setNextPC(Addr val)
7682308SN/A    {
7692308SN/A        nextPC = val;
7702308SN/A    }
7712190SN/A
7722935Sksewell@umich.edu    /** Set the next NPC of this instruction (the target in Mips or Sparc).*/
7734636Sgblack@eecs.umich.edu    void setNextNPC(Addr val)
7742935Sksewell@umich.edu    {
7754632Sgblack@eecs.umich.edu#if ISA_HAS_DELAY_SLOT
7762935Sksewell@umich.edu        nextNPC = val;
7774632Sgblack@eecs.umich.edu#endif
7782935Sksewell@umich.edu    }
7792935Sksewell@umich.edu
7804636Sgblack@eecs.umich.edu    void setNextMicroPC(Addr val)
7814636Sgblack@eecs.umich.edu    {
7824636Sgblack@eecs.umich.edu        nextMicroPC = val;
7834636Sgblack@eecs.umich.edu    }
7844636Sgblack@eecs.umich.edu
7852702Sktlim@umich.edu    /** Sets the ASID. */
7862292SN/A    void setASID(short addr_space_id) { asid = addr_space_id; }
7872292SN/A
7882702Sktlim@umich.edu    /** Sets the thread id. */
7892702Sktlim@umich.edu    void setTid(unsigned tid) { threadNumber = tid; }
7902292SN/A
7912731Sktlim@umich.edu    /** Sets the pointer to the thread state. */
7922702Sktlim@umich.edu    void setThreadState(ImplState *state) { thread = state; }
7931060SN/A
7942731Sktlim@umich.edu    /** Returns the thread context. */
7952680Sktlim@umich.edu    ThreadContext *tcBase() { return thread->getTC(); }
7961464SN/A
7971464SN/A  private:
7981684SN/A    /** Instruction effective address.
7991684SN/A     *  @todo: Consider if this is necessary or not.
8001684SN/A     */
8011464SN/A    Addr instEffAddr;
8022292SN/A
8031684SN/A    /** Whether or not the effective address calculation is completed.
8041684SN/A     *  @todo: Consider if this is necessary or not.
8051684SN/A     */
8061464SN/A    bool eaCalcDone;
8071464SN/A
8084032Sktlim@umich.edu    /** Is this instruction's memory access uncacheable. */
8094032Sktlim@umich.edu    bool isUncacheable;
8104032Sktlim@umich.edu
8114032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
8124032Sktlim@umich.edu    bool reqMade;
8134032Sktlim@umich.edu
8141464SN/A  public:
8151684SN/A    /** Sets the effective address. */
8161464SN/A    void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
8171684SN/A
8181684SN/A    /** Returns the effective address. */
8191464SN/A    const Addr &getEA() const { return instEffAddr; }
8201684SN/A
8211684SN/A    /** Returns whether or not the eff. addr. calculation has been completed. */
8221464SN/A    bool doneEACalc() { return eaCalcDone; }
8231684SN/A
8241684SN/A    /** Returns whether or not the eff. addr. source registers are ready. */
8251464SN/A    bool eaSrcsReady();
8261681SN/A
8272292SN/A    /** Whether or not the memory operation is done. */
8282292SN/A    bool memOpDone;
8292292SN/A
8304032Sktlim@umich.edu    /** Is this instruction's memory access uncacheable. */
8314032Sktlim@umich.edu    bool uncacheable() { return isUncacheable; }
8324032Sktlim@umich.edu
8334032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
8344032Sktlim@umich.edu    bool hasRequest() { return reqMade; }
8354032Sktlim@umich.edu
8361681SN/A  public:
8371684SN/A    /** Load queue index. */
8381681SN/A    int16_t lqIdx;
8391684SN/A
8401684SN/A    /** Store queue index. */
8411681SN/A    int16_t sqIdx;
8422292SN/A
8432292SN/A    /** Iterator pointing to this BaseDynInst in the list of all insts. */
8442292SN/A    ListIt instListIt;
8452292SN/A
8462292SN/A    /** Returns iterator to this instruction in the list of all insts. */
8472292SN/A    ListIt &getInstListIt() { return instListIt; }
8482292SN/A
8492292SN/A    /** Sets iterator for this instruction in the list of all insts. */
8502292SN/A    void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
8513326Sktlim@umich.edu
8523326Sktlim@umich.edu  public:
8533326Sktlim@umich.edu    /** Returns the number of consecutive store conditional failures. */
8543326Sktlim@umich.edu    unsigned readStCondFailures()
8553326Sktlim@umich.edu    { return thread->storeCondFailures; }
8563326Sktlim@umich.edu
8573326Sktlim@umich.edu    /** Sets the number of consecutive store conditional failures. */
8583326Sktlim@umich.edu    void setStCondFailures(unsigned sc_failures)
8593326Sktlim@umich.edu    { thread->storeCondFailures = sc_failures; }
8601060SN/A};
8611060SN/A
8621060SN/Atemplate<class Impl>
8635177Sgblack@eecs.umich.eduFault
8645177Sgblack@eecs.umich.eduBaseDynInst<Impl>::translateDataReadAddr(Addr vaddr, Addr &paddr,
8655177Sgblack@eecs.umich.edu        int size, unsigned flags)
8665177Sgblack@eecs.umich.edu{
8675177Sgblack@eecs.umich.edu    if (traceData) {
8685177Sgblack@eecs.umich.edu        traceData->setAddr(vaddr);
8695177Sgblack@eecs.umich.edu    }
8705177Sgblack@eecs.umich.edu
8715177Sgblack@eecs.umich.edu    reqMade = true;
8725177Sgblack@eecs.umich.edu    Request *req = new Request();
8735177Sgblack@eecs.umich.edu    req->setVirt(asid, vaddr, size, flags, PC);
8745714Shsul@eecs.umich.edu    req->setThreadContext(thread->contextId(), threadNumber);
8755177Sgblack@eecs.umich.edu
8765177Sgblack@eecs.umich.edu    fault = cpu->translateDataReadReq(req, thread);
8775177Sgblack@eecs.umich.edu
8785177Sgblack@eecs.umich.edu    if (fault == NoFault)
8795177Sgblack@eecs.umich.edu        paddr = req->getPaddr();
8805177Sgblack@eecs.umich.edu
8815177Sgblack@eecs.umich.edu    delete req;
8825177Sgblack@eecs.umich.edu    return fault;
8835177Sgblack@eecs.umich.edu}
8845177Sgblack@eecs.umich.edu
8855177Sgblack@eecs.umich.edutemplate<class Impl>
8861060SN/Atemplate<class T>
8872132SN/Ainline Fault
8881060SN/ABaseDynInst<Impl>::read(Addr addr, T &data, unsigned flags)
8891060SN/A{
8904032Sktlim@umich.edu    reqMade = true;
8914032Sktlim@umich.edu    Request *req = new Request();
8924032Sktlim@umich.edu    req->setVirt(asid, addr, sizeof(T), flags, this->PC);
8935714Shsul@eecs.umich.edu    req->setThreadContext(thread->contextId(), threadNumber);
8942292SN/A
8952690Sktlim@umich.edu    fault = cpu->translateDataReadReq(req, thread);
8961060SN/A
8974032Sktlim@umich.edu    if (req->isUncacheable())
8984032Sktlim@umich.edu        isUncacheable = true;
8994032Sktlim@umich.edu
9002678Sktlim@umich.edu    if (fault == NoFault) {
9012678Sktlim@umich.edu        effAddr = req->getVaddr();
9024032Sktlim@umich.edu        effAddrValid = true;
9032678Sktlim@umich.edu        physEffAddr = req->getPaddr();
9042678Sktlim@umich.edu        memReqFlags = req->getFlags();
9051060SN/A
9062690Sktlim@umich.edu#if 0
9072292SN/A        if (cpu->system->memctrl->badaddr(physEffAddr)) {
9082292SN/A            fault = TheISA::genMachineCheckFault();
9092292SN/A            data = (T)-1;
9102292SN/A            this->setExecuted();
9112292SN/A        } else {
9122292SN/A            fault = cpu->read(req, data, lqIdx);
9132292SN/A        }
9142292SN/A#else
9151681SN/A        fault = cpu->read(req, data, lqIdx);
9162632Sstever@eecs.umich.edu#endif
9171684SN/A    } else {
9181060SN/A        // Return a fixed value to keep simulation deterministic even
9191060SN/A        // along misspeculated paths.
9201060SN/A        data = (T)-1;
9212292SN/A
9222292SN/A        // Commit will have to clean up whatever happened.  Set this
9232292SN/A        // instruction as executed.
9242292SN/A        this->setExecuted();
9254032Sktlim@umich.edu        delete req;
9261060SN/A    }
9271060SN/A
9281060SN/A    if (traceData) {
9291060SN/A        traceData->setAddr(addr);
9301060SN/A        traceData->setData(data);
9311060SN/A    }
9321060SN/A
9331060SN/A    return fault;
9341060SN/A}
9351060SN/A
9361060SN/Atemplate<class Impl>
9375177Sgblack@eecs.umich.eduFault
9385177Sgblack@eecs.umich.eduBaseDynInst<Impl>::translateDataWriteAddr(Addr vaddr, Addr &paddr,
9395177Sgblack@eecs.umich.edu        int size, unsigned flags)
9405177Sgblack@eecs.umich.edu{
9415177Sgblack@eecs.umich.edu    if (traceData) {
9425177Sgblack@eecs.umich.edu        traceData->setAddr(vaddr);
9435177Sgblack@eecs.umich.edu    }
9445177Sgblack@eecs.umich.edu
9455177Sgblack@eecs.umich.edu    reqMade = true;
9465177Sgblack@eecs.umich.edu    Request *req = new Request();
9475177Sgblack@eecs.umich.edu    req->setVirt(asid, vaddr, size, flags, PC);
9485714Shsul@eecs.umich.edu    req->setThreadContext(thread->contextId(), threadNumber);
9495177Sgblack@eecs.umich.edu
9505177Sgblack@eecs.umich.edu    fault = cpu->translateDataWriteReq(req, thread);
9515177Sgblack@eecs.umich.edu
9525177Sgblack@eecs.umich.edu    if (fault == NoFault)
9535177Sgblack@eecs.umich.edu        paddr = req->getPaddr();
9545177Sgblack@eecs.umich.edu
9555177Sgblack@eecs.umich.edu    delete req;
9565177Sgblack@eecs.umich.edu    return fault;
9575177Sgblack@eecs.umich.edu}
9585177Sgblack@eecs.umich.edu
9595177Sgblack@eecs.umich.edutemplate<class Impl>
9601060SN/Atemplate<class T>
9612132SN/Ainline Fault
9621060SN/ABaseDynInst<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res)
9631060SN/A{
9641060SN/A    if (traceData) {
9651060SN/A        traceData->setAddr(addr);
9661060SN/A        traceData->setData(data);
9671060SN/A    }
9681060SN/A
9694032Sktlim@umich.edu    reqMade = true;
9704032Sktlim@umich.edu    Request *req = new Request();
9712669Sktlim@umich.edu    req->setVirt(asid, addr, sizeof(T), flags, this->PC);
9725714Shsul@eecs.umich.edu    req->setThreadContext(thread->contextId(), threadNumber);
9731060SN/A
9742690Sktlim@umich.edu    fault = cpu->translateDataWriteReq(req, thread);
9751060SN/A
9764032Sktlim@umich.edu    if (req->isUncacheable())
9774032Sktlim@umich.edu        isUncacheable = true;
9784032Sktlim@umich.edu
9792090SN/A    if (fault == NoFault) {
9802678Sktlim@umich.edu        effAddr = req->getVaddr();
9814032Sktlim@umich.edu        effAddrValid = true;
9822678Sktlim@umich.edu        physEffAddr = req->getPaddr();
9832678Sktlim@umich.edu        memReqFlags = req->getFlags();
9844350Sgblack@eecs.umich.edu
9854350Sgblack@eecs.umich.edu        if (req->isCondSwap()) {
9864350Sgblack@eecs.umich.edu            assert(res);
9874350Sgblack@eecs.umich.edu            req->setExtraData(*res);
9884350Sgblack@eecs.umich.edu        }
9892690Sktlim@umich.edu#if 0
9902292SN/A        if (cpu->system->memctrl->badaddr(physEffAddr)) {
9912292SN/A            fault = TheISA::genMachineCheckFault();
9922292SN/A        } else {
9932292SN/A            fault = cpu->write(req, data, sqIdx);
9942292SN/A        }
9952292SN/A#else
9961681SN/A        fault = cpu->write(req, data, sqIdx);
9972632Sstever@eecs.umich.edu#endif
9984032Sktlim@umich.edu    } else {
9994032Sktlim@umich.edu        delete req;
10001060SN/A    }
10011060SN/A
10021060SN/A    return fault;
10031060SN/A}
10041060SN/A
10051464SN/A#endif // __CPU_BASE_DYN_INST_HH__
1006