base_dyn_inst.hh revision 7783
11060SN/A/*
22702Sktlim@umich.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan
36973Stjones1@inf.ed.ac.uk * Copyright (c) 2009 The University of Edinburgh
41060SN/A * All rights reserved.
51060SN/A *
61060SN/A * Redistribution and use in source and binary forms, with or without
71060SN/A * modification, are permitted provided that the following conditions are
81060SN/A * met: redistributions of source code must retain the above copyright
91060SN/A * notice, this list of conditions and the following disclaimer;
101060SN/A * redistributions in binary form must reproduce the above copyright
111060SN/A * notice, this list of conditions and the following disclaimer in the
121060SN/A * documentation and/or other materials provided with the distribution;
131060SN/A * neither the name of the copyright holders nor the names of its
141060SN/A * contributors may be used to endorse or promote products derived from
151060SN/A * this software without specific prior written permission.
161060SN/A *
171060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
306973Stjones1@inf.ed.ac.uk *          Timothy M. Jones
311060SN/A */
321060SN/A
331464SN/A#ifndef __CPU_BASE_DYN_INST_HH__
341464SN/A#define __CPU_BASE_DYN_INST_HH__
351060SN/A
362731Sktlim@umich.edu#include <bitset>
372292SN/A#include <list>
381464SN/A#include <string>
391060SN/A
402669Sktlim@umich.edu#include "arch/faults.hh"
417720Sgblack@eecs.umich.edu#include "arch/utility.hh"
421060SN/A#include "base/fast_alloc.hh"
431060SN/A#include "base/trace.hh"
441858SN/A#include "config/full_system.hh"
456658Snate@binkert.org#include "config/the_isa.hh"
463770Sgblack@eecs.umich.edu#include "cpu/o3/comm.hh"
471464SN/A#include "cpu/exetrace.hh"
481464SN/A#include "cpu/inst_seq.hh"
492669Sktlim@umich.edu#include "cpu/op_class.hh"
501060SN/A#include "cpu/static_inst.hh"
516973Stjones1@inf.ed.ac.uk#include "cpu/translation.hh"
522669Sktlim@umich.edu#include "mem/packet.hh"
537678Sgblack@eecs.umich.edu#include "sim/byteswap.hh"
542292SN/A#include "sim/system.hh"
556023Snate@binkert.org#include "sim/tlb.hh"
561060SN/A
571060SN/A/**
581060SN/A * @file
591060SN/A * Defines a dynamic instruction context.
601060SN/A */
611060SN/A
621061SN/A// Forward declaration.
631061SN/Aclass StaticInstPtr;
641060SN/A
651060SN/Atemplate <class Impl>
661061SN/Aclass BaseDynInst : public FastAlloc, public RefCounted
671060SN/A{
681060SN/A  public:
691060SN/A    // Typedef for the CPU.
702733Sktlim@umich.edu    typedef typename Impl::CPUType ImplCPU;
712733Sktlim@umich.edu    typedef typename ImplCPU::ImplState ImplState;
721060SN/A
732292SN/A    // Logical register index type.
742107SN/A    typedef TheISA::RegIndex RegIndex;
752690Sktlim@umich.edu    // Integer register type.
762107SN/A    typedef TheISA::IntReg IntReg;
772690Sktlim@umich.edu    // Floating point register type.
782690Sktlim@umich.edu    typedef TheISA::FloatReg FloatReg;
791060SN/A
802292SN/A    // The DynInstPtr type.
812292SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
822292SN/A
832292SN/A    // The list of instructions iterator type.
842292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
852292SN/A
861060SN/A    enum {
875543Ssaidi@eecs.umich.edu        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        /// Max source regs
885543Ssaidi@eecs.umich.edu        MaxInstDestRegs = TheISA::MaxInstDestRegs,      /// Max dest regs
891060SN/A    };
901060SN/A
912292SN/A    /** The StaticInst used by this BaseDynInst. */
922107SN/A    StaticInstPtr staticInst;
931060SN/A
941060SN/A    ////////////////////////////////////////////
951060SN/A    //
961060SN/A    // INSTRUCTION EXECUTION
971060SN/A    //
981060SN/A    ////////////////////////////////////////////
992292SN/A    /** InstRecord that tracks this instructions. */
1001060SN/A    Trace::InstRecord *traceData;
1011060SN/A
1025358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
1035358Sgblack@eecs.umich.edu    {
1045358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1055358Sgblack@eecs.umich.edu    }
1065358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
1075358Sgblack@eecs.umich.edu    {
1085358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1095358Sgblack@eecs.umich.edu    }
1105358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
1115358Sgblack@eecs.umich.edu    {
1125358Sgblack@eecs.umich.edu        cpu->demapPage(vaddr, asn);
1135358Sgblack@eecs.umich.edu    }
1145358Sgblack@eecs.umich.edu
1152292SN/A    /**
1162292SN/A     * Does a read to a given address.
1172292SN/A     * @param addr The address to read.
1182292SN/A     * @param data The read's data is written into this parameter.
1192292SN/A     * @param flags The request's flags.
1202292SN/A     * @return Returns any fault due to the read.
1212292SN/A     */
1221060SN/A    template <class T>
1232132SN/A    Fault read(Addr addr, T &data, unsigned flags);
1241060SN/A
1257520Sgblack@eecs.umich.edu    Fault readBytes(Addr addr, uint8_t *data, unsigned size, unsigned flags);
1267520Sgblack@eecs.umich.edu
1272292SN/A    /**
1282292SN/A     * Does a write to a given address.
1292292SN/A     * @param data The data to be written.
1302292SN/A     * @param addr The address to write to.
1312292SN/A     * @param flags The request's flags.
1322292SN/A     * @param res The result of the write (for load locked/store conditionals).
1332292SN/A     * @return Returns any fault due to the write.
1342292SN/A     */
1351060SN/A    template <class T>
1366973Stjones1@inf.ed.ac.uk    Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
1376973Stjones1@inf.ed.ac.uk
1387520Sgblack@eecs.umich.edu    Fault writeBytes(uint8_t *data, unsigned size,
1397520Sgblack@eecs.umich.edu                     Addr addr, unsigned flags, uint64_t *res);
1407520Sgblack@eecs.umich.edu
1416974Stjones1@inf.ed.ac.uk    /** Splits a request in two if it crosses a dcache block. */
1426974Stjones1@inf.ed.ac.uk    void splitRequest(RequestPtr req, RequestPtr &sreqLow,
1436974Stjones1@inf.ed.ac.uk                      RequestPtr &sreqHigh);
1446974Stjones1@inf.ed.ac.uk
1456973Stjones1@inf.ed.ac.uk    /** Initiate a DTB address translation. */
1466974Stjones1@inf.ed.ac.uk    void initiateTranslation(RequestPtr req, RequestPtr sreqLow,
1476974Stjones1@inf.ed.ac.uk                             RequestPtr sreqHigh, uint64_t *res,
1486973Stjones1@inf.ed.ac.uk                             BaseTLB::Mode mode);
1496973Stjones1@inf.ed.ac.uk
1506973Stjones1@inf.ed.ac.uk    /** Finish a DTB address translation. */
1516973Stjones1@inf.ed.ac.uk    void finishTranslation(WholeTranslationState *state);
1521060SN/A
1531684SN/A    /** @todo: Consider making this private. */
1541060SN/A  public:
1551060SN/A    /** The sequence number of the instruction. */
1561060SN/A    InstSeqNum seqNum;
1571060SN/A
1582731Sktlim@umich.edu    enum Status {
1592731Sktlim@umich.edu        IqEntry,                 /// Instruction is in the IQ
1602731Sktlim@umich.edu        RobEntry,                /// Instruction is in the ROB
1612731Sktlim@umich.edu        LsqEntry,                /// Instruction is in the LSQ
1622731Sktlim@umich.edu        Completed,               /// Instruction has completed
1632731Sktlim@umich.edu        ResultReady,             /// Instruction has its result
1642731Sktlim@umich.edu        CanIssue,                /// Instruction can issue and execute
1652731Sktlim@umich.edu        Issued,                  /// Instruction has issued
1662731Sktlim@umich.edu        Executed,                /// Instruction has executed
1672731Sktlim@umich.edu        CanCommit,               /// Instruction can commit
1682731Sktlim@umich.edu        AtCommit,                /// Instruction has reached commit
1692731Sktlim@umich.edu        Committed,               /// Instruction has committed
1702731Sktlim@umich.edu        Squashed,                /// Instruction is squashed
1712731Sktlim@umich.edu        SquashedInIQ,            /// Instruction is squashed in the IQ
1722731Sktlim@umich.edu        SquashedInLSQ,           /// Instruction is squashed in the LSQ
1732731Sktlim@umich.edu        SquashedInROB,           /// Instruction is squashed in the ROB
1742731Sktlim@umich.edu        RecoverInst,             /// Is a recover instruction
1752731Sktlim@umich.edu        BlockingInst,            /// Is a blocking instruction
1762731Sktlim@umich.edu        ThreadsyncWait,          /// Is a thread synchronization instruction
1772731Sktlim@umich.edu        SerializeBefore,         /// Needs to serialize on
1782731Sktlim@umich.edu                                 /// instructions ahead of it
1792731Sktlim@umich.edu        SerializeAfter,          /// Needs to serialize instructions behind it
1802731Sktlim@umich.edu        SerializeHandled,        /// Serialization has been handled
1812731Sktlim@umich.edu        NumStatus
1822731Sktlim@umich.edu    };
1832292SN/A
1842731Sktlim@umich.edu    /** The status of this BaseDynInst.  Several bits can be set. */
1852731Sktlim@umich.edu    std::bitset<NumStatus> status;
1861060SN/A
1871060SN/A    /** The thread this instruction is from. */
1886221Snate@binkert.org    ThreadID threadNumber;
1891060SN/A
1901060SN/A    /** data address space ID, for loads & stores. */
1911060SN/A    short asid;
1921060SN/A
1932292SN/A    /** How many source registers are ready. */
1942292SN/A    unsigned readyRegs;
1952292SN/A
1962733Sktlim@umich.edu    /** Pointer to the Impl's CPU object. */
1972733Sktlim@umich.edu    ImplCPU *cpu;
1981060SN/A
1992680Sktlim@umich.edu    /** Pointer to the thread state. */
2002292SN/A    ImplState *thread;
2011060SN/A
2021060SN/A    /** The kind of fault this instruction has generated. */
2032132SN/A    Fault fault;
2041060SN/A
2052702Sktlim@umich.edu    /** Pointer to the data for the memory access. */
2062669Sktlim@umich.edu    uint8_t *memData;
2072292SN/A
2081060SN/A    /** The effective virtual address (lds & stores only). */
2091060SN/A    Addr effAddr;
2101060SN/A
2114032Sktlim@umich.edu    /** Is the effective virtual address valid. */
2124032Sktlim@umich.edu    bool effAddrValid;
2134032Sktlim@umich.edu
2141060SN/A    /** The effective physical address. */
2151060SN/A    Addr physEffAddr;
2161060SN/A
2171060SN/A    /** Effective virtual address for a copy source. */
2181060SN/A    Addr copySrcEffAddr;
2191060SN/A
2201060SN/A    /** Effective physical address for a copy source. */
2211060SN/A    Addr copySrcPhysEffAddr;
2221060SN/A
2231060SN/A    /** The memory request flags (from translation). */
2241060SN/A    unsigned memReqFlags;
2251060SN/A
2261464SN/A    union Result {
2271464SN/A        uint64_t integer;
2282356SN/A//        float fp;
2291464SN/A        double dbl;
2301464SN/A    };
2311060SN/A
2321464SN/A    /** The result of the instruction; assumes for now that there's only one
2331464SN/A     *  destination register.
2341464SN/A     */
2351464SN/A    Result instResult;
2361060SN/A
2373326Sktlim@umich.edu    /** Records changes to result? */
2383326Sktlim@umich.edu    bool recordResult;
2393326Sktlim@umich.edu
2407597Sminkyu.jeong@arm.com    /** Did this instruction execute, or is it predicated false */
2417597Sminkyu.jeong@arm.com    bool predicate;
2427597Sminkyu.jeong@arm.com
2433965Sgblack@eecs.umich.edu  protected:
2447720Sgblack@eecs.umich.edu    /** PC state for this instruction. */
2457720Sgblack@eecs.umich.edu    TheISA::PCState pc;
2461060SN/A
2477720Sgblack@eecs.umich.edu    /** Predicted PC state after this instruction. */
2487720Sgblack@eecs.umich.edu    TheISA::PCState predPC;
2494636Sgblack@eecs.umich.edu
2503794Sgblack@eecs.umich.edu    /** If this is a branch that was predicted taken */
2513794Sgblack@eecs.umich.edu    bool predTaken;
2523794Sgblack@eecs.umich.edu
2533965Sgblack@eecs.umich.edu  public:
2543965Sgblack@eecs.umich.edu
2552292SN/A#ifdef DEBUG
2562292SN/A    void dumpSNList();
2572292SN/A#endif
2582292SN/A
2592292SN/A    /** Whether or not the source register is ready.
2602292SN/A     *  @todo: Not sure this should be here vs the derived class.
2611060SN/A     */
2621060SN/A    bool _readySrcRegIdx[MaxInstSrcRegs];
2631060SN/A
2643770Sgblack@eecs.umich.edu  protected:
2653770Sgblack@eecs.umich.edu    /** Flattened register index of the destination registers of this
2663770Sgblack@eecs.umich.edu     *  instruction.
2673770Sgblack@eecs.umich.edu     */
2683770Sgblack@eecs.umich.edu    TheISA::RegIndex _flatDestRegIdx[TheISA::MaxInstDestRegs];
2693770Sgblack@eecs.umich.edu
2703770Sgblack@eecs.umich.edu    /** Flattened register index of the source registers of this
2713770Sgblack@eecs.umich.edu     *  instruction.
2723770Sgblack@eecs.umich.edu     */
2733770Sgblack@eecs.umich.edu    TheISA::RegIndex _flatSrcRegIdx[TheISA::MaxInstSrcRegs];
2743770Sgblack@eecs.umich.edu
2753770Sgblack@eecs.umich.edu    /** Physical register index of the destination registers of this
2763770Sgblack@eecs.umich.edu     *  instruction.
2773770Sgblack@eecs.umich.edu     */
2783770Sgblack@eecs.umich.edu    PhysRegIndex _destRegIdx[TheISA::MaxInstDestRegs];
2793770Sgblack@eecs.umich.edu
2803770Sgblack@eecs.umich.edu    /** Physical register index of the source registers of this
2813770Sgblack@eecs.umich.edu     *  instruction.
2823770Sgblack@eecs.umich.edu     */
2833770Sgblack@eecs.umich.edu    PhysRegIndex _srcRegIdx[TheISA::MaxInstSrcRegs];
2843770Sgblack@eecs.umich.edu
2853770Sgblack@eecs.umich.edu    /** Physical register index of the previous producers of the
2863770Sgblack@eecs.umich.edu     *  architected destinations.
2873770Sgblack@eecs.umich.edu     */
2883770Sgblack@eecs.umich.edu    PhysRegIndex _prevDestRegIdx[TheISA::MaxInstDestRegs];
2893770Sgblack@eecs.umich.edu
2901060SN/A  public:
2913770Sgblack@eecs.umich.edu
2923770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th destination
2933770Sgblack@eecs.umich.edu     *  register.
2943770Sgblack@eecs.umich.edu     */
2953770Sgblack@eecs.umich.edu    PhysRegIndex renamedDestRegIdx(int idx) const
2963770Sgblack@eecs.umich.edu    {
2973770Sgblack@eecs.umich.edu        return _destRegIdx[idx];
2983770Sgblack@eecs.umich.edu    }
2993770Sgblack@eecs.umich.edu
3003770Sgblack@eecs.umich.edu    /** Returns the physical register index of the i'th source register. */
3013770Sgblack@eecs.umich.edu    PhysRegIndex renamedSrcRegIdx(int idx) const
3023770Sgblack@eecs.umich.edu    {
3033770Sgblack@eecs.umich.edu        return _srcRegIdx[idx];
3043770Sgblack@eecs.umich.edu    }
3053770Sgblack@eecs.umich.edu
3063770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th destination
3073770Sgblack@eecs.umich.edu     *  register.
3083770Sgblack@eecs.umich.edu     */
3093770Sgblack@eecs.umich.edu    TheISA::RegIndex flattenedDestRegIdx(int idx) const
3103770Sgblack@eecs.umich.edu    {
3113770Sgblack@eecs.umich.edu        return _flatDestRegIdx[idx];
3123770Sgblack@eecs.umich.edu    }
3133770Sgblack@eecs.umich.edu
3143770Sgblack@eecs.umich.edu    /** Returns the flattened register index of the i'th source register */
3153770Sgblack@eecs.umich.edu    TheISA::RegIndex flattenedSrcRegIdx(int idx) const
3163770Sgblack@eecs.umich.edu    {
3173770Sgblack@eecs.umich.edu        return _flatSrcRegIdx[idx];
3183770Sgblack@eecs.umich.edu    }
3193770Sgblack@eecs.umich.edu
3203770Sgblack@eecs.umich.edu    /** Returns the physical register index of the previous physical register
3213770Sgblack@eecs.umich.edu     *  that remapped to the same logical register index.
3223770Sgblack@eecs.umich.edu     */
3233770Sgblack@eecs.umich.edu    PhysRegIndex prevDestRegIdx(int idx) const
3243770Sgblack@eecs.umich.edu    {
3253770Sgblack@eecs.umich.edu        return _prevDestRegIdx[idx];
3263770Sgblack@eecs.umich.edu    }
3273770Sgblack@eecs.umich.edu
3283770Sgblack@eecs.umich.edu    /** Renames a destination register to a physical register.  Also records
3293770Sgblack@eecs.umich.edu     *  the previous physical register that the logical register mapped to.
3303770Sgblack@eecs.umich.edu     */
3313770Sgblack@eecs.umich.edu    void renameDestReg(int idx,
3323770Sgblack@eecs.umich.edu                       PhysRegIndex renamed_dest,
3333770Sgblack@eecs.umich.edu                       PhysRegIndex previous_rename)
3343770Sgblack@eecs.umich.edu    {
3353770Sgblack@eecs.umich.edu        _destRegIdx[idx] = renamed_dest;
3363770Sgblack@eecs.umich.edu        _prevDestRegIdx[idx] = previous_rename;
3373770Sgblack@eecs.umich.edu    }
3383770Sgblack@eecs.umich.edu
3393770Sgblack@eecs.umich.edu    /** Renames a source logical register to the physical register which
3403770Sgblack@eecs.umich.edu     *  has/will produce that logical register's result.
3413770Sgblack@eecs.umich.edu     *  @todo: add in whether or not the source register is ready.
3423770Sgblack@eecs.umich.edu     */
3433770Sgblack@eecs.umich.edu    void renameSrcReg(int idx, PhysRegIndex renamed_src)
3443770Sgblack@eecs.umich.edu    {
3453770Sgblack@eecs.umich.edu        _srcRegIdx[idx] = renamed_src;
3463770Sgblack@eecs.umich.edu    }
3473770Sgblack@eecs.umich.edu
3483770Sgblack@eecs.umich.edu    /** Flattens a source architectural register index into a logical index.
3493770Sgblack@eecs.umich.edu     */
3503770Sgblack@eecs.umich.edu    void flattenSrcReg(int idx, TheISA::RegIndex flattened_src)
3513770Sgblack@eecs.umich.edu    {
3523770Sgblack@eecs.umich.edu        _flatSrcRegIdx[idx] = flattened_src;
3533770Sgblack@eecs.umich.edu    }
3543770Sgblack@eecs.umich.edu
3553770Sgblack@eecs.umich.edu    /** Flattens a destination architectural register index into a logical
3563770Sgblack@eecs.umich.edu     * index.
3573770Sgblack@eecs.umich.edu     */
3583770Sgblack@eecs.umich.edu    void flattenDestReg(int idx, TheISA::RegIndex flattened_dest)
3593770Sgblack@eecs.umich.edu    {
3603770Sgblack@eecs.umich.edu        _flatDestRegIdx[idx] = flattened_dest;
3613770Sgblack@eecs.umich.edu    }
3624636Sgblack@eecs.umich.edu    /** BaseDynInst constructor given a binary instruction.
3634636Sgblack@eecs.umich.edu     *  @param staticInst A StaticInstPtr to the underlying instruction.
3647720Sgblack@eecs.umich.edu     *  @param pc The PC state for the instruction.
3657720Sgblack@eecs.umich.edu     *  @param predPC The predicted next PC state for the instruction.
3664636Sgblack@eecs.umich.edu     *  @param seq_num The sequence number of the instruction.
3674636Sgblack@eecs.umich.edu     *  @param cpu Pointer to the instruction's CPU.
3684636Sgblack@eecs.umich.edu     */
3697720Sgblack@eecs.umich.edu    BaseDynInst(StaticInstPtr staticInst, TheISA::PCState pc,
3707720Sgblack@eecs.umich.edu                TheISA::PCState predPC, InstSeqNum seq_num, ImplCPU *cpu);
3713770Sgblack@eecs.umich.edu
3722292SN/A    /** BaseDynInst constructor given a binary instruction.
3732292SN/A     *  @param inst The binary instruction.
3747720Sgblack@eecs.umich.edu     *  @param _pc The PC state for the instruction.
3757720Sgblack@eecs.umich.edu     *  @param _predPC The predicted next PC state for the instruction.
3762292SN/A     *  @param seq_num The sequence number of the instruction.
3772292SN/A     *  @param cpu Pointer to the instruction's CPU.
3782292SN/A     */
3797720Sgblack@eecs.umich.edu    BaseDynInst(TheISA::ExtMachInst inst, TheISA::PCState pc,
3807720Sgblack@eecs.umich.edu                TheISA::PCState predPC, InstSeqNum seq_num, ImplCPU *cpu);
3811060SN/A
3822292SN/A    /** BaseDynInst constructor given a StaticInst pointer.
3832292SN/A     *  @param _staticInst The StaticInst for this BaseDynInst.
3842292SN/A     */
3852107SN/A    BaseDynInst(StaticInstPtr &_staticInst);
3861060SN/A
3871060SN/A    /** BaseDynInst destructor. */
3881060SN/A    ~BaseDynInst();
3891060SN/A
3901464SN/A  private:
3911684SN/A    /** Function to initialize variables in the constructors. */
3921464SN/A    void initVars();
3931060SN/A
3941464SN/A  public:
3951060SN/A    /** Dumps out contents of this BaseDynInst. */
3961060SN/A    void dump();
3971060SN/A
3981060SN/A    /** Dumps out contents of this BaseDynInst into given string. */
3991060SN/A    void dump(std::string &outstring);
4001060SN/A
4013326Sktlim@umich.edu    /** Read this CPU's ID. */
4025712Shsul@eecs.umich.edu    int cpuId() { return cpu->cpuId(); }
4033326Sktlim@umich.edu
4045714Shsul@eecs.umich.edu    /** Read this context's system-wide ID **/
4055714Shsul@eecs.umich.edu    int contextId() { return thread->contextId(); }
4065714Shsul@eecs.umich.edu
4071060SN/A    /** Returns the fault type. */
4082132SN/A    Fault getFault() { return fault; }
4091060SN/A
4101060SN/A    /** Checks whether or not this instruction has had its branch target
4111060SN/A     *  calculated yet.  For now it is not utilized and is hacked to be
4121060SN/A     *  always false.
4132292SN/A     *  @todo: Actually use this instruction.
4141060SN/A     */
4151060SN/A    bool doneTargCalc() { return false; }
4161060SN/A
4177720Sgblack@eecs.umich.edu    /** Set the predicted target of this current instruction. */
4187720Sgblack@eecs.umich.edu    void setPredTarg(const TheISA::PCState &_predPC)
4193965Sgblack@eecs.umich.edu    {
4207720Sgblack@eecs.umich.edu        predPC = _predPC;
4213965Sgblack@eecs.umich.edu    }
4222935Sksewell@umich.edu
4237720Sgblack@eecs.umich.edu    const TheISA::PCState &readPredTarg() { return predPC; }
4241060SN/A
4253794Sgblack@eecs.umich.edu    /** Returns the predicted PC immediately after the branch. */
4267720Sgblack@eecs.umich.edu    Addr predInstAddr() { return predPC.instAddr(); }
4273794Sgblack@eecs.umich.edu
4283794Sgblack@eecs.umich.edu    /** Returns the predicted PC two instructions after the branch */
4297720Sgblack@eecs.umich.edu    Addr predNextInstAddr() { return predPC.nextInstAddr(); }
4301060SN/A
4314636Sgblack@eecs.umich.edu    /** Returns the predicted micro PC after the branch */
4327720Sgblack@eecs.umich.edu    Addr predMicroPC() { return predPC.microPC(); }
4334636Sgblack@eecs.umich.edu
4341060SN/A    /** Returns whether the instruction was predicted taken or not. */
4353794Sgblack@eecs.umich.edu    bool readPredTaken()
4363794Sgblack@eecs.umich.edu    {
4373794Sgblack@eecs.umich.edu        return predTaken;
4383794Sgblack@eecs.umich.edu    }
4393794Sgblack@eecs.umich.edu
4403794Sgblack@eecs.umich.edu    void setPredTaken(bool predicted_taken)
4413794Sgblack@eecs.umich.edu    {
4423794Sgblack@eecs.umich.edu        predTaken = predicted_taken;
4433794Sgblack@eecs.umich.edu    }
4441060SN/A
4451060SN/A    /** Returns whether the instruction mispredicted. */
4462935Sksewell@umich.edu    bool mispredicted()
4473794Sgblack@eecs.umich.edu    {
4487720Sgblack@eecs.umich.edu        TheISA::PCState tempPC = pc;
4497720Sgblack@eecs.umich.edu        TheISA::advancePC(tempPC, staticInst);
4507720Sgblack@eecs.umich.edu        return !(tempPC == predPC);
4513794Sgblack@eecs.umich.edu    }
4523794Sgblack@eecs.umich.edu
4531060SN/A    //
4541060SN/A    //  Instruction types.  Forward checks to StaticInst object.
4551060SN/A    //
4565543Ssaidi@eecs.umich.edu    bool isNop()          const { return staticInst->isNop(); }
4575543Ssaidi@eecs.umich.edu    bool isMemRef()       const { return staticInst->isMemRef(); }
4585543Ssaidi@eecs.umich.edu    bool isLoad()         const { return staticInst->isLoad(); }
4595543Ssaidi@eecs.umich.edu    bool isStore()        const { return staticInst->isStore(); }
4602336SN/A    bool isStoreConditional() const
4612336SN/A    { return staticInst->isStoreConditional(); }
4621060SN/A    bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
4631060SN/A    bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
4641060SN/A    bool isCopy()         const { return staticInst->isCopy(); }
4655543Ssaidi@eecs.umich.edu    bool isInteger()      const { return staticInst->isInteger(); }
4665543Ssaidi@eecs.umich.edu    bool isFloating()     const { return staticInst->isFloating(); }
4675543Ssaidi@eecs.umich.edu    bool isControl()      const { return staticInst->isControl(); }
4685543Ssaidi@eecs.umich.edu    bool isCall()         const { return staticInst->isCall(); }
4695543Ssaidi@eecs.umich.edu    bool isReturn()       const { return staticInst->isReturn(); }
4705543Ssaidi@eecs.umich.edu    bool isDirectCtrl()   const { return staticInst->isDirectCtrl(); }
4711060SN/A    bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
4725543Ssaidi@eecs.umich.edu    bool isCondCtrl()     const { return staticInst->isCondCtrl(); }
4735543Ssaidi@eecs.umich.edu    bool isUncondCtrl()   const { return staticInst->isUncondCtrl(); }
4742935Sksewell@umich.edu    bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
4751060SN/A    bool isThreadSync()   const { return staticInst->isThreadSync(); }
4761060SN/A    bool isSerializing()  const { return staticInst->isSerializing(); }
4772292SN/A    bool isSerializeBefore() const
4782731Sktlim@umich.edu    { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
4792292SN/A    bool isSerializeAfter() const
4802731Sktlim@umich.edu    { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
4811060SN/A    bool isMemBarrier()   const { return staticInst->isMemBarrier(); }
4821060SN/A    bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
4831060SN/A    bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
4842292SN/A    bool isQuiesce() const { return staticInst->isQuiesce(); }
4852336SN/A    bool isIprAccess() const { return staticInst->isIprAccess(); }
4862308SN/A    bool isUnverifiable() const { return staticInst->isUnverifiable(); }
4874828Sgblack@eecs.umich.edu    bool isSyscall() const { return staticInst->isSyscall(); }
4884654Sgblack@eecs.umich.edu    bool isMacroop() const { return staticInst->isMacroop(); }
4894654Sgblack@eecs.umich.edu    bool isMicroop() const { return staticInst->isMicroop(); }
4904636Sgblack@eecs.umich.edu    bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
4914654Sgblack@eecs.umich.edu    bool isLastMicroop() const { return staticInst->isLastMicroop(); }
4924654Sgblack@eecs.umich.edu    bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
4934636Sgblack@eecs.umich.edu    bool isMicroBranch() const { return staticInst->isMicroBranch(); }
4942292SN/A
4952292SN/A    /** Temporarily sets this instruction as a serialize before instruction. */
4962731Sktlim@umich.edu    void setSerializeBefore() { status.set(SerializeBefore); }
4972292SN/A
4982292SN/A    /** Clears the serializeBefore part of this instruction. */
4992731Sktlim@umich.edu    void clearSerializeBefore() { status.reset(SerializeBefore); }
5002292SN/A
5012292SN/A    /** Checks if this serializeBefore is only temporarily set. */
5022731Sktlim@umich.edu    bool isTempSerializeBefore() { return status[SerializeBefore]; }
5032292SN/A
5042292SN/A    /** Temporarily sets this instruction as a serialize after instruction. */
5052731Sktlim@umich.edu    void setSerializeAfter() { status.set(SerializeAfter); }
5062292SN/A
5072292SN/A    /** Clears the serializeAfter part of this instruction.*/
5082731Sktlim@umich.edu    void clearSerializeAfter() { status.reset(SerializeAfter); }
5092292SN/A
5102292SN/A    /** Checks if this serializeAfter is only temporarily set. */
5112731Sktlim@umich.edu    bool isTempSerializeAfter() { return status[SerializeAfter]; }
5122292SN/A
5132731Sktlim@umich.edu    /** Sets the serialization part of this instruction as handled. */
5142731Sktlim@umich.edu    void setSerializeHandled() { status.set(SerializeHandled); }
5152292SN/A
5162292SN/A    /** Checks if the serialization part of this instruction has been
5172292SN/A     *  handled.  This does not apply to the temporary serializing
5182292SN/A     *  state; it only applies to this instruction's own permanent
5192292SN/A     *  serializing state.
5202292SN/A     */
5212731Sktlim@umich.edu    bool isSerializeHandled() { return status[SerializeHandled]; }
5221060SN/A
5231464SN/A    /** Returns the opclass of this instruction. */
5241464SN/A    OpClass opClass() const { return staticInst->opClass(); }
5251464SN/A
5261464SN/A    /** Returns the branch target address. */
5277720Sgblack@eecs.umich.edu    TheISA::PCState branchTarget() const
5287720Sgblack@eecs.umich.edu    { return staticInst->branchTarget(pc); }
5291464SN/A
5302292SN/A    /** Returns the number of source registers. */
5315543Ssaidi@eecs.umich.edu    int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
5321684SN/A
5332292SN/A    /** Returns the number of destination registers. */
5341060SN/A    int8_t numDestRegs() const { return staticInst->numDestRegs(); }
5351060SN/A
5361060SN/A    // the following are used to track physical register usage
5371060SN/A    // for machines with separate int & FP reg files
5381060SN/A    int8_t numFPDestRegs()  const { return staticInst->numFPDestRegs(); }
5391060SN/A    int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
5401060SN/A
5411060SN/A    /** Returns the logical register index of the i'th destination register. */
5422292SN/A    RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
5431060SN/A
5441060SN/A    /** Returns the logical register index of the i'th source register. */
5452292SN/A    RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
5461060SN/A
5471684SN/A    /** Returns the result of an integer instruction. */
5481464SN/A    uint64_t readIntResult() { return instResult.integer; }
5491684SN/A
5501684SN/A    /** Returns the result of a floating point instruction. */
5512356SN/A    float readFloatResult() { return (float)instResult.dbl; }
5521684SN/A
5531684SN/A    /** Returns the result of a floating point (double) instruction. */
5541464SN/A    double readDoubleResult() { return instResult.dbl; }
5551060SN/A
5562702Sktlim@umich.edu    /** Records an integer register being set to a value. */
5573735Sstever@eecs.umich.edu    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
5581060SN/A    {
5593326Sktlim@umich.edu        if (recordResult)
5603326Sktlim@umich.edu            instResult.integer = val;
5611060SN/A    }
5621060SN/A
5632702Sktlim@umich.edu    /** Records an fp register being set to a value. */
5643735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
5653735Sstever@eecs.umich.edu                            int width)
5662690Sktlim@umich.edu    {
5673326Sktlim@umich.edu        if (recordResult) {
5683326Sktlim@umich.edu            if (width == 32)
5693326Sktlim@umich.edu                instResult.dbl = (double)val;
5703326Sktlim@umich.edu            else if (width == 64)
5713326Sktlim@umich.edu                instResult.dbl = val;
5723326Sktlim@umich.edu            else
5733326Sktlim@umich.edu                panic("Unsupported width!");
5743326Sktlim@umich.edu        }
5752690Sktlim@umich.edu    }
5762690Sktlim@umich.edu
5772702Sktlim@umich.edu    /** Records an fp register being set to a value. */
5783735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
5791060SN/A    {
5803326Sktlim@umich.edu        if (recordResult)
5813326Sktlim@umich.edu            instResult.dbl = (double)val;
5822308SN/A    }
5831060SN/A
5842702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
5853735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val,
5863735Sstever@eecs.umich.edu                                int width)
5872308SN/A    {
5883326Sktlim@umich.edu        if (recordResult)
5893326Sktlim@umich.edu            instResult.integer = val;
5902308SN/A    }
5911060SN/A
5922702Sktlim@umich.edu    /** Records an fp register being set to an integer value. */
5933735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx, uint64_t val)
5942308SN/A    {
5953326Sktlim@umich.edu        if (recordResult)
5963326Sktlim@umich.edu            instResult.integer = val;
5971060SN/A    }
5981060SN/A
5992190SN/A    /** Records that one of the source registers is ready. */
6002292SN/A    void markSrcRegReady();
6012190SN/A
6022331SN/A    /** Marks a specific register as ready. */
6032292SN/A    void markSrcRegReady(RegIndex src_idx);
6042190SN/A
6051684SN/A    /** Returns if a source register is ready. */
6061464SN/A    bool isReadySrcRegIdx(int idx) const
6071464SN/A    {
6081464SN/A        return this->_readySrcRegIdx[idx];
6091464SN/A    }
6101464SN/A
6111684SN/A    /** Sets this instruction as completed. */
6122731Sktlim@umich.edu    void setCompleted() { status.set(Completed); }
6131464SN/A
6142292SN/A    /** Returns whether or not this instruction is completed. */
6152731Sktlim@umich.edu    bool isCompleted() const { return status[Completed]; }
6161464SN/A
6172731Sktlim@umich.edu    /** Marks the result as ready. */
6182731Sktlim@umich.edu    void setResultReady() { status.set(ResultReady); }
6192308SN/A
6202731Sktlim@umich.edu    /** Returns whether or not the result is ready. */
6212731Sktlim@umich.edu    bool isResultReady() const { return status[ResultReady]; }
6222308SN/A
6231060SN/A    /** Sets this instruction as ready to issue. */
6242731Sktlim@umich.edu    void setCanIssue() { status.set(CanIssue); }
6251060SN/A
6261060SN/A    /** Returns whether or not this instruction is ready to issue. */
6272731Sktlim@umich.edu    bool readyToIssue() const { return status[CanIssue]; }
6281060SN/A
6294032Sktlim@umich.edu    /** Clears this instruction being able to issue. */
6304032Sktlim@umich.edu    void clearCanIssue() { status.reset(CanIssue); }
6314032Sktlim@umich.edu
6321060SN/A    /** Sets this instruction as issued from the IQ. */
6332731Sktlim@umich.edu    void setIssued() { status.set(Issued); }
6341060SN/A
6351060SN/A    /** Returns whether or not this instruction has issued. */
6362731Sktlim@umich.edu    bool isIssued() const { return status[Issued]; }
6371060SN/A
6384032Sktlim@umich.edu    /** Clears this instruction as being issued. */
6394032Sktlim@umich.edu    void clearIssued() { status.reset(Issued); }
6404032Sktlim@umich.edu
6411060SN/A    /** Sets this instruction as executed. */
6422731Sktlim@umich.edu    void setExecuted() { status.set(Executed); }
6431060SN/A
6441060SN/A    /** Returns whether or not this instruction has executed. */
6452731Sktlim@umich.edu    bool isExecuted() const { return status[Executed]; }
6461060SN/A
6471060SN/A    /** Sets this instruction as ready to commit. */
6482731Sktlim@umich.edu    void setCanCommit() { status.set(CanCommit); }
6491060SN/A
6501061SN/A    /** Clears this instruction as being ready to commit. */
6512731Sktlim@umich.edu    void clearCanCommit() { status.reset(CanCommit); }
6521061SN/A
6531060SN/A    /** Returns whether or not this instruction is ready to commit. */
6542731Sktlim@umich.edu    bool readyToCommit() const { return status[CanCommit]; }
6552731Sktlim@umich.edu
6562731Sktlim@umich.edu    void setAtCommit() { status.set(AtCommit); }
6572731Sktlim@umich.edu
6582731Sktlim@umich.edu    bool isAtCommit() { return status[AtCommit]; }
6591060SN/A
6602292SN/A    /** Sets this instruction as committed. */
6612731Sktlim@umich.edu    void setCommitted() { status.set(Committed); }
6622292SN/A
6632292SN/A    /** Returns whether or not this instruction is committed. */
6642731Sktlim@umich.edu    bool isCommitted() const { return status[Committed]; }
6652292SN/A
6661060SN/A    /** Sets this instruction as squashed. */
6672731Sktlim@umich.edu    void setSquashed() { status.set(Squashed); }
6681060SN/A
6691060SN/A    /** Returns whether or not this instruction is squashed. */
6702731Sktlim@umich.edu    bool isSquashed() const { return status[Squashed]; }
6711060SN/A
6722292SN/A    //Instruction Queue Entry
6732292SN/A    //-----------------------
6742292SN/A    /** Sets this instruction as a entry the IQ. */
6752731Sktlim@umich.edu    void setInIQ() { status.set(IqEntry); }
6762292SN/A
6772292SN/A    /** Sets this instruction as a entry the IQ. */
6782731Sktlim@umich.edu    void clearInIQ() { status.reset(IqEntry); }
6792731Sktlim@umich.edu
6802731Sktlim@umich.edu    /** Returns whether or not this instruction has issued. */
6812731Sktlim@umich.edu    bool isInIQ() const { return status[IqEntry]; }
6822292SN/A
6831060SN/A    /** Sets this instruction as squashed in the IQ. */
6842731Sktlim@umich.edu    void setSquashedInIQ() { status.set(SquashedInIQ); status.set(Squashed);}
6851060SN/A
6861060SN/A    /** Returns whether or not this instruction is squashed in the IQ. */
6872731Sktlim@umich.edu    bool isSquashedInIQ() const { return status[SquashedInIQ]; }
6882292SN/A
6892292SN/A
6902292SN/A    //Load / Store Queue Functions
6912292SN/A    //-----------------------
6922292SN/A    /** Sets this instruction as a entry the LSQ. */
6932731Sktlim@umich.edu    void setInLSQ() { status.set(LsqEntry); }
6942292SN/A
6952292SN/A    /** Sets this instruction as a entry the LSQ. */
6962731Sktlim@umich.edu    void removeInLSQ() { status.reset(LsqEntry); }
6972731Sktlim@umich.edu
6982731Sktlim@umich.edu    /** Returns whether or not this instruction is in the LSQ. */
6992731Sktlim@umich.edu    bool isInLSQ() const { return status[LsqEntry]; }
7002292SN/A
7012292SN/A    /** Sets this instruction as squashed in the LSQ. */
7022731Sktlim@umich.edu    void setSquashedInLSQ() { status.set(SquashedInLSQ);}
7032292SN/A
7042292SN/A    /** Returns whether or not this instruction is squashed in the LSQ. */
7052731Sktlim@umich.edu    bool isSquashedInLSQ() const { return status[SquashedInLSQ]; }
7062292SN/A
7072292SN/A
7082292SN/A    //Reorder Buffer Functions
7092292SN/A    //-----------------------
7102292SN/A    /** Sets this instruction as a entry the ROB. */
7112731Sktlim@umich.edu    void setInROB() { status.set(RobEntry); }
7122292SN/A
7132292SN/A    /** Sets this instruction as a entry the ROB. */
7142731Sktlim@umich.edu    void clearInROB() { status.reset(RobEntry); }
7152731Sktlim@umich.edu
7162731Sktlim@umich.edu    /** Returns whether or not this instruction is in the ROB. */
7172731Sktlim@umich.edu    bool isInROB() const { return status[RobEntry]; }
7182292SN/A
7192292SN/A    /** Sets this instruction as squashed in the ROB. */
7202731Sktlim@umich.edu    void setSquashedInROB() { status.set(SquashedInROB); }
7212292SN/A
7222292SN/A    /** Returns whether or not this instruction is squashed in the ROB. */
7232731Sktlim@umich.edu    bool isSquashedInROB() const { return status[SquashedInROB]; }
7242292SN/A
7257720Sgblack@eecs.umich.edu    /** Read the PC state of this instruction. */
7267720Sgblack@eecs.umich.edu    const TheISA::PCState pcState() const { return pc; }
7277720Sgblack@eecs.umich.edu
7287720Sgblack@eecs.umich.edu    /** Set the PC state of this instruction. */
7297720Sgblack@eecs.umich.edu    const void pcState(const TheISA::PCState &val) { pc = val; }
7307720Sgblack@eecs.umich.edu
7311060SN/A    /** Read the PC of this instruction. */
7327720Sgblack@eecs.umich.edu    const Addr instAddr() const { return pc.instAddr(); }
7337720Sgblack@eecs.umich.edu
7347720Sgblack@eecs.umich.edu    /** Read the PC of the next instruction. */
7357720Sgblack@eecs.umich.edu    const Addr nextInstAddr() const { return pc.nextInstAddr(); }
7361060SN/A
7374636Sgblack@eecs.umich.edu    /**Read the micro PC of this instruction. */
7387720Sgblack@eecs.umich.edu    const Addr microPC() const { return pc.microPC(); }
7394636Sgblack@eecs.umich.edu
7407597Sminkyu.jeong@arm.com    bool readPredicate()
7417597Sminkyu.jeong@arm.com    {
7427597Sminkyu.jeong@arm.com        return predicate;
7437597Sminkyu.jeong@arm.com    }
7447597Sminkyu.jeong@arm.com
7457597Sminkyu.jeong@arm.com    void setPredicate(bool val)
7467597Sminkyu.jeong@arm.com    {
7477597Sminkyu.jeong@arm.com        predicate = val;
7487600Sminkyu.jeong@arm.com
7497600Sminkyu.jeong@arm.com        if (traceData) {
7507600Sminkyu.jeong@arm.com            traceData->setPredicate(val);
7517600Sminkyu.jeong@arm.com        }
7527597Sminkyu.jeong@arm.com    }
7537597Sminkyu.jeong@arm.com
7542702Sktlim@umich.edu    /** Sets the ASID. */
7552292SN/A    void setASID(short addr_space_id) { asid = addr_space_id; }
7562292SN/A
7572702Sktlim@umich.edu    /** Sets the thread id. */
7586221Snate@binkert.org    void setTid(ThreadID tid) { threadNumber = tid; }
7592292SN/A
7602731Sktlim@umich.edu    /** Sets the pointer to the thread state. */
7612702Sktlim@umich.edu    void setThreadState(ImplState *state) { thread = state; }
7621060SN/A
7632731Sktlim@umich.edu    /** Returns the thread context. */
7642680Sktlim@umich.edu    ThreadContext *tcBase() { return thread->getTC(); }
7651464SN/A
7661464SN/A  private:
7671684SN/A    /** Instruction effective address.
7681684SN/A     *  @todo: Consider if this is necessary or not.
7691684SN/A     */
7701464SN/A    Addr instEffAddr;
7712292SN/A
7721684SN/A    /** Whether or not the effective address calculation is completed.
7731684SN/A     *  @todo: Consider if this is necessary or not.
7741684SN/A     */
7751464SN/A    bool eaCalcDone;
7761464SN/A
7774032Sktlim@umich.edu    /** Is this instruction's memory access uncacheable. */
7784032Sktlim@umich.edu    bool isUncacheable;
7794032Sktlim@umich.edu
7804032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
7814032Sktlim@umich.edu    bool reqMade;
7824032Sktlim@umich.edu
7831464SN/A  public:
7841684SN/A    /** Sets the effective address. */
7851464SN/A    void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
7861684SN/A
7871684SN/A    /** Returns the effective address. */
7881464SN/A    const Addr &getEA() const { return instEffAddr; }
7891684SN/A
7901684SN/A    /** Returns whether or not the eff. addr. calculation has been completed. */
7911464SN/A    bool doneEACalc() { return eaCalcDone; }
7921684SN/A
7931684SN/A    /** Returns whether or not the eff. addr. source registers are ready. */
7941464SN/A    bool eaSrcsReady();
7951681SN/A
7962292SN/A    /** Whether or not the memory operation is done. */
7972292SN/A    bool memOpDone;
7982292SN/A
7994032Sktlim@umich.edu    /** Is this instruction's memory access uncacheable. */
8004032Sktlim@umich.edu    bool uncacheable() { return isUncacheable; }
8014032Sktlim@umich.edu
8024032Sktlim@umich.edu    /** Has this instruction generated a memory request. */
8034032Sktlim@umich.edu    bool hasRequest() { return reqMade; }
8044032Sktlim@umich.edu
8051681SN/A  public:
8061684SN/A    /** Load queue index. */
8071681SN/A    int16_t lqIdx;
8081684SN/A
8091684SN/A    /** Store queue index. */
8101681SN/A    int16_t sqIdx;
8112292SN/A
8122292SN/A    /** Iterator pointing to this BaseDynInst in the list of all insts. */
8132292SN/A    ListIt instListIt;
8142292SN/A
8152292SN/A    /** Returns iterator to this instruction in the list of all insts. */
8162292SN/A    ListIt &getInstListIt() { return instListIt; }
8172292SN/A
8182292SN/A    /** Sets iterator for this instruction in the list of all insts. */
8192292SN/A    void setInstListIt(ListIt _instListIt) { instListIt = _instListIt; }
8203326Sktlim@umich.edu
8213326Sktlim@umich.edu  public:
8223326Sktlim@umich.edu    /** Returns the number of consecutive store conditional failures. */
8233326Sktlim@umich.edu    unsigned readStCondFailures()
8243326Sktlim@umich.edu    { return thread->storeCondFailures; }
8253326Sktlim@umich.edu
8263326Sktlim@umich.edu    /** Sets the number of consecutive store conditional failures. */
8273326Sktlim@umich.edu    void setStCondFailures(unsigned sc_failures)
8283326Sktlim@umich.edu    { thread->storeCondFailures = sc_failures; }
8291060SN/A};
8301060SN/A
8311060SN/Atemplate<class Impl>
8327520Sgblack@eecs.umich.eduFault
8337520Sgblack@eecs.umich.eduBaseDynInst<Impl>::readBytes(Addr addr, uint8_t *data,
8347520Sgblack@eecs.umich.edu                             unsigned size, unsigned flags)
8351060SN/A{
8364032Sktlim@umich.edu    reqMade = true;
8377720Sgblack@eecs.umich.edu    Request *req = new Request(asid, addr, size, flags, this->pc.instAddr(),
8386429Ssteve.reinhardt@amd.com                               thread->contextId(), threadNumber);
8392292SN/A
8406974Stjones1@inf.ed.ac.uk    Request *sreqLow = NULL;
8416974Stjones1@inf.ed.ac.uk    Request *sreqHigh = NULL;
8426974Stjones1@inf.ed.ac.uk
8436974Stjones1@inf.ed.ac.uk    // Only split the request if the ISA supports unaligned accesses.
8446974Stjones1@inf.ed.ac.uk    if (TheISA::HasUnalignedMemAcc) {
8456974Stjones1@inf.ed.ac.uk        splitRequest(req, sreqLow, sreqHigh);
8466974Stjones1@inf.ed.ac.uk    }
8476974Stjones1@inf.ed.ac.uk    initiateTranslation(req, sreqLow, sreqHigh, NULL, BaseTLB::Read);
8484032Sktlim@umich.edu
8492678Sktlim@umich.edu    if (fault == NoFault) {
8502678Sktlim@umich.edu        effAddr = req->getVaddr();
8514032Sktlim@umich.edu        effAddrValid = true;
8526975Stjones1@inf.ed.ac.uk        fault = cpu->read(req, sreqLow, sreqHigh, data, lqIdx);
8536973Stjones1@inf.ed.ac.uk    } else {
8542292SN/A        // Commit will have to clean up whatever happened.  Set this
8552292SN/A        // instruction as executed.
8562292SN/A        this->setExecuted();
8571060SN/A    }
8581060SN/A
8597577SAli.Saidi@ARM.com    if (fault != NoFault) {
8607577SAli.Saidi@ARM.com        // Return a fixed value to keep simulation deterministic even
8617577SAli.Saidi@ARM.com        // along misspeculated paths.
8627783SGiacomo.Gabrielli@arm.com        if (data)
8637783SGiacomo.Gabrielli@arm.com            bzero(data, size);
8647577SAli.Saidi@ARM.com    }
8657577SAli.Saidi@ARM.com
8661060SN/A    if (traceData) {
8671060SN/A        traceData->setAddr(addr);
8681060SN/A    }
8691060SN/A
8701060SN/A    return fault;
8711060SN/A}
8721060SN/A
8731060SN/Atemplate<class Impl>
8741060SN/Atemplate<class T>
8752132SN/Ainline Fault
8767520Sgblack@eecs.umich.eduBaseDynInst<Impl>::read(Addr addr, T &data, unsigned flags)
8777520Sgblack@eecs.umich.edu{
8787520Sgblack@eecs.umich.edu    Fault fault = readBytes(addr, (uint8_t *)&data, sizeof(T), flags);
8797520Sgblack@eecs.umich.edu
8807520Sgblack@eecs.umich.edu    data = TheISA::gtoh(data);
8817520Sgblack@eecs.umich.edu
8827520Sgblack@eecs.umich.edu    if (traceData) {
8837520Sgblack@eecs.umich.edu        traceData->setData(data);
8847520Sgblack@eecs.umich.edu    }
8857520Sgblack@eecs.umich.edu
8867520Sgblack@eecs.umich.edu    return fault;
8877520Sgblack@eecs.umich.edu}
8887520Sgblack@eecs.umich.edu
8897520Sgblack@eecs.umich.edutemplate<class Impl>
8907520Sgblack@eecs.umich.eduFault
8917520Sgblack@eecs.umich.eduBaseDynInst<Impl>::writeBytes(uint8_t *data, unsigned size,
8927520Sgblack@eecs.umich.edu                              Addr addr, unsigned flags, uint64_t *res)
8931060SN/A{
8941060SN/A    if (traceData) {
8951060SN/A        traceData->setAddr(addr);
8961060SN/A    }
8971060SN/A
8984032Sktlim@umich.edu    reqMade = true;
8997720Sgblack@eecs.umich.edu    Request *req = new Request(asid, addr, size, flags, this->pc.instAddr(),
9006429Ssteve.reinhardt@amd.com                               thread->contextId(), threadNumber);
9011060SN/A
9026974Stjones1@inf.ed.ac.uk    Request *sreqLow = NULL;
9036974Stjones1@inf.ed.ac.uk    Request *sreqHigh = NULL;
9046974Stjones1@inf.ed.ac.uk
9056974Stjones1@inf.ed.ac.uk    // Only split the request if the ISA supports unaligned accesses.
9066974Stjones1@inf.ed.ac.uk    if (TheISA::HasUnalignedMemAcc) {
9076974Stjones1@inf.ed.ac.uk        splitRequest(req, sreqLow, sreqHigh);
9086974Stjones1@inf.ed.ac.uk    }
9096974Stjones1@inf.ed.ac.uk    initiateTranslation(req, sreqLow, sreqHigh, res, BaseTLB::Write);
9104032Sktlim@umich.edu
9112090SN/A    if (fault == NoFault) {
9122678Sktlim@umich.edu        effAddr = req->getVaddr();
9134032Sktlim@umich.edu        effAddrValid = true;
9146975Stjones1@inf.ed.ac.uk        fault = cpu->write(req, sreqLow, sreqHigh, data, sqIdx);
9151060SN/A    }
9161060SN/A
9171060SN/A    return fault;
9181060SN/A}
9191060SN/A
9206973Stjones1@inf.ed.ac.uktemplate<class Impl>
9217520Sgblack@eecs.umich.edutemplate<class T>
9227520Sgblack@eecs.umich.eduinline Fault
9237520Sgblack@eecs.umich.eduBaseDynInst<Impl>::write(T data, Addr addr, unsigned flags, uint64_t *res)
9247520Sgblack@eecs.umich.edu{
9257520Sgblack@eecs.umich.edu    if (traceData) {
9267520Sgblack@eecs.umich.edu        traceData->setData(data);
9277520Sgblack@eecs.umich.edu    }
9287520Sgblack@eecs.umich.edu    data = TheISA::htog(data);
9297520Sgblack@eecs.umich.edu    return writeBytes((uint8_t *)&data, sizeof(T), addr, flags, res);
9307520Sgblack@eecs.umich.edu}
9317520Sgblack@eecs.umich.edu
9327520Sgblack@eecs.umich.edutemplate<class Impl>
9336973Stjones1@inf.ed.ac.ukinline void
9346974Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::splitRequest(RequestPtr req, RequestPtr &sreqLow,
9356974Stjones1@inf.ed.ac.uk                                RequestPtr &sreqHigh)
9366974Stjones1@inf.ed.ac.uk{
9376974Stjones1@inf.ed.ac.uk    // Check to see if the request crosses the next level block boundary.
9386974Stjones1@inf.ed.ac.uk    unsigned block_size = cpu->getDcachePort()->peerBlockSize();
9396974Stjones1@inf.ed.ac.uk    Addr addr = req->getVaddr();
9406974Stjones1@inf.ed.ac.uk    Addr split_addr = roundDown(addr + req->getSize() - 1, block_size);
9416974Stjones1@inf.ed.ac.uk    assert(split_addr <= addr || split_addr - addr < block_size);
9426974Stjones1@inf.ed.ac.uk
9436974Stjones1@inf.ed.ac.uk    // Spans two blocks.
9446974Stjones1@inf.ed.ac.uk    if (split_addr > addr) {
9456974Stjones1@inf.ed.ac.uk        req->splitOnVaddr(split_addr, sreqLow, sreqHigh);
9466974Stjones1@inf.ed.ac.uk    }
9476974Stjones1@inf.ed.ac.uk}
9486974Stjones1@inf.ed.ac.uk
9496974Stjones1@inf.ed.ac.uktemplate<class Impl>
9506974Stjones1@inf.ed.ac.ukinline void
9516974Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::initiateTranslation(RequestPtr req, RequestPtr sreqLow,
9526974Stjones1@inf.ed.ac.uk                                       RequestPtr sreqHigh, uint64_t *res,
9536973Stjones1@inf.ed.ac.uk                                       BaseTLB::Mode mode)
9546973Stjones1@inf.ed.ac.uk{
9556974Stjones1@inf.ed.ac.uk    if (!TheISA::HasUnalignedMemAcc || sreqLow == NULL) {
9566974Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
9576974Stjones1@inf.ed.ac.uk            new WholeTranslationState(req, NULL, res, mode);
9586974Stjones1@inf.ed.ac.uk
9596974Stjones1@inf.ed.ac.uk        // One translation if the request isn't split.
9606974Stjones1@inf.ed.ac.uk        DataTranslation<BaseDynInst<Impl> > *trans =
9616974Stjones1@inf.ed.ac.uk            new DataTranslation<BaseDynInst<Impl> >(this, state);
9626974Stjones1@inf.ed.ac.uk        cpu->dtb->translateTiming(req, thread->getTC(), trans, mode);
9636974Stjones1@inf.ed.ac.uk    } else {
9646974Stjones1@inf.ed.ac.uk        WholeTranslationState *state =
9656974Stjones1@inf.ed.ac.uk            new WholeTranslationState(req, sreqLow, sreqHigh, NULL, res, mode);
9666974Stjones1@inf.ed.ac.uk
9676974Stjones1@inf.ed.ac.uk        // Two translations when the request is split.
9686974Stjones1@inf.ed.ac.uk        DataTranslation<BaseDynInst<Impl> > *stransLow =
9696974Stjones1@inf.ed.ac.uk            new DataTranslation<BaseDynInst<Impl> >(this, state, 0);
9706974Stjones1@inf.ed.ac.uk        DataTranslation<BaseDynInst<Impl> > *stransHigh =
9716974Stjones1@inf.ed.ac.uk            new DataTranslation<BaseDynInst<Impl> >(this, state, 1);
9726974Stjones1@inf.ed.ac.uk
9736974Stjones1@inf.ed.ac.uk        cpu->dtb->translateTiming(sreqLow, thread->getTC(), stransLow, mode);
9746974Stjones1@inf.ed.ac.uk        cpu->dtb->translateTiming(sreqHigh, thread->getTC(), stransHigh, mode);
9756974Stjones1@inf.ed.ac.uk    }
9766973Stjones1@inf.ed.ac.uk}
9776973Stjones1@inf.ed.ac.uk
9786973Stjones1@inf.ed.ac.uktemplate<class Impl>
9796973Stjones1@inf.ed.ac.ukinline void
9806973Stjones1@inf.ed.ac.ukBaseDynInst<Impl>::finishTranslation(WholeTranslationState *state)
9816973Stjones1@inf.ed.ac.uk{
9826973Stjones1@inf.ed.ac.uk    fault = state->getFault();
9836973Stjones1@inf.ed.ac.uk
9846973Stjones1@inf.ed.ac.uk    if (state->isUncacheable())
9856973Stjones1@inf.ed.ac.uk        isUncacheable = true;
9866973Stjones1@inf.ed.ac.uk
9876973Stjones1@inf.ed.ac.uk    if (fault == NoFault) {
9886973Stjones1@inf.ed.ac.uk        physEffAddr = state->getPaddr();
9896973Stjones1@inf.ed.ac.uk        memReqFlags = state->getFlags();
9906973Stjones1@inf.ed.ac.uk
9916973Stjones1@inf.ed.ac.uk        if (state->mainReq->isCondSwap()) {
9926973Stjones1@inf.ed.ac.uk            assert(state->res);
9936973Stjones1@inf.ed.ac.uk            state->mainReq->setExtraData(*state->res);
9946973Stjones1@inf.ed.ac.uk        }
9956973Stjones1@inf.ed.ac.uk
9966973Stjones1@inf.ed.ac.uk    } else {
9976973Stjones1@inf.ed.ac.uk        state->deleteReqs();
9986973Stjones1@inf.ed.ac.uk    }
9996973Stjones1@inf.ed.ac.uk    delete state;
10006973Stjones1@inf.ed.ac.uk}
10016973Stjones1@inf.ed.ac.uk
10021464SN/A#endif // __CPU_BASE_DYN_INST_HH__
1003