dyn_inst.hh revision 8557
112954Sgabeblack@google.com/*
212954Sgabeblack@google.com * Copyright (c) 2010 ARM Limited
312954Sgabeblack@google.com * All rights reserved
412954Sgabeblack@google.com *
512954Sgabeblack@google.com * The license below extends only to copyright in the software and shall
612954Sgabeblack@google.com * not be construed as granting a license to any other intellectual
712954Sgabeblack@google.com * property including but not limited to intellectual property relating
812954Sgabeblack@google.com * to a hardware implementation of the functionality of the software
912954Sgabeblack@google.com * licensed hereunder.  You may use the software subject to the license
1012954Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated
1112954Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software,
1212954Sgabeblack@google.com * modified or unmodified, in source code or in binary form.
1312954Sgabeblack@google.com *
1412954Sgabeblack@google.com * Copyright (c) 2004-2006 The Regents of The University of Michigan
1512954Sgabeblack@google.com * All rights reserved.
1612954Sgabeblack@google.com *
1712954Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1812954Sgabeblack@google.com * modification, are permitted provided that the following conditions are
1912954Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
2012954Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
2112954Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
2212954Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2312954Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
2412954Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
2512954Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
2612954Sgabeblack@google.com * this software without specific prior written permission.
2712954Sgabeblack@google.com *
2812954Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2912954Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3012954Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3112954Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3212954Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3313059Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3413059Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3512954Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3612954Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3712954Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3812954Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3912954Sgabeblack@google.com *
4012954Sgabeblack@google.com * Authors: Kevin Lim
4112954Sgabeblack@google.com */
4212954Sgabeblack@google.com
4312954Sgabeblack@google.com#ifndef __CPU_O3_DYN_INST_HH__
4413059Sgabeblack@google.com#define __CPU_O3_DYN_INST_HH__
4512954Sgabeblack@google.com
4613059Sgabeblack@google.com#include "arch/isa_traits.hh"
4712954Sgabeblack@google.com#include "config/the_isa.hh"
4812954Sgabeblack@google.com#include "cpu/o3/cpu.hh"
4912954Sgabeblack@google.com#include "cpu/o3/isa_specific.hh"
5012954Sgabeblack@google.com#include "cpu/base_dyn_inst.hh"
5112954Sgabeblack@google.com#include "cpu/inst_seq.hh"
5212954Sgabeblack@google.com
5312954Sgabeblack@google.comclass Packet;
5412954Sgabeblack@google.com
5512954Sgabeblack@google.com/**
5612954Sgabeblack@google.com * Mostly implementation & ISA specific AlphaDynInst. As with most
5712954Sgabeblack@google.com * other classes in the new CPU model, it is templated on the Impl to
5813059Sgabeblack@google.com * allow for passing in of all types, such as the CPU type and the ISA
5913059Sgabeblack@google.com * type. The AlphaDynInst serves as the primary interface to the CPU
6012954Sgabeblack@google.com * for instructions that are executing.
6112954Sgabeblack@google.com */
6212954Sgabeblack@google.comtemplate <class Impl>
63class BaseO3DynInst : public BaseDynInst<Impl>
64{
65  public:
66    /** Typedef for the CPU. */
67    typedef typename Impl::O3CPU O3CPU;
68
69    /** Binary machine instruction type. */
70    typedef TheISA::MachInst MachInst;
71    /** Extended machine instruction type. */
72    typedef TheISA::ExtMachInst ExtMachInst;
73    /** Logical register index type. */
74    typedef TheISA::RegIndex RegIndex;
75    /** Integer register index type. */
76    typedef TheISA::IntReg   IntReg;
77    typedef TheISA::FloatReg FloatReg;
78    typedef TheISA::FloatRegBits FloatRegBits;
79    /** Misc register index type. */
80    typedef TheISA::MiscReg  MiscReg;
81
82    enum {
83        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        //< Max source regs
84        MaxInstDestRegs = TheISA::MaxInstDestRegs,      //< Max dest regs
85    };
86
87  public:
88    /** BaseDynInst constructor given a binary instruction. */
89    BaseO3DynInst(StaticInstPtr staticInst, StaticInstPtr macroop,
90                  TheISA::PCState pc, TheISA::PCState predPC,
91                  InstSeqNum seq_num, O3CPU *cpu);
92
93    /** BaseDynInst constructor given a static inst pointer. */
94    BaseO3DynInst(StaticInstPtr _staticInst, StaticInstPtr _macroop);
95
96    /** Executes the instruction.*/
97    Fault execute();
98
99    /** Initiates the access.  Only valid for memory operations. */
100    Fault initiateAcc();
101
102    /** Completes the access.  Only valid for memory operations. */
103    Fault completeAcc(PacketPtr pkt);
104
105  private:
106    /** Initializes variables. */
107    void initVars();
108
109  protected:
110    /** Indexes of the destination misc. registers. They are needed to defer
111     * the write accesses to the misc. registers until the commit stage, when
112     * the instruction is out of its speculative state.
113     */
114    int _destMiscRegIdx[MaxInstDestRegs];
115    /** Values to be written to the destination misc. registers. */
116    MiscReg _destMiscRegVal[MaxInstDestRegs];
117    /** Number of destination misc. registers. */
118    int _numDestMiscRegs;
119
120  public:
121
122#if TRACING_ON
123    /** Tick records used for the pipeline activity viewer. */
124    Tick fetchTick;
125    Tick decodeTick;
126    Tick renameTick;
127    Tick dispatchTick;
128    Tick issueTick;
129    Tick completeTick;
130#endif
131
132    /** Reads a misc. register, including any side-effects the read
133     * might have as defined by the architecture.
134     */
135    MiscReg readMiscReg(int misc_reg)
136    {
137        return this->cpu->readMiscReg(misc_reg, this->threadNumber);
138    }
139
140    /** Sets a misc. register, including any side-effects the write
141     * might have as defined by the architecture.
142     */
143    void setMiscReg(int misc_reg, const MiscReg &val)
144    {
145        /** Writes to misc. registers are recorded and deferred until the
146         * commit stage, when updateMiscRegs() is called.
147         */
148        _destMiscRegIdx[_numDestMiscRegs] = misc_reg;
149        _destMiscRegVal[_numDestMiscRegs] = val;
150        _numDestMiscRegs++;
151    }
152
153    /** Reads a misc. register, including any side-effects the read
154     * might have as defined by the architecture.
155     */
156    TheISA::MiscReg readMiscRegOperand(const StaticInst *si, int idx)
157    {
158        return this->cpu->readMiscReg(
159                si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag,
160                this->threadNumber);
161    }
162
163    /** Sets a misc. register, including any side-effects the write
164     * might have as defined by the architecture.
165     */
166    void setMiscRegOperand(const StaticInst *si, int idx,
167                                     const MiscReg &val)
168    {
169        int misc_reg = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
170        setMiscReg(misc_reg, val);
171    }
172
173    /** Called at the commit stage to update the misc. registers. */
174    void updateMiscRegs()
175    {
176        // @todo: Pretty convoluted way to avoid squashing from happening when
177        // using the TC during an instruction's execution (specifically for
178        // instructions that have side-effects that use the TC).  Fix this.
179        // See cpu/o3/dyn_inst_impl.hh.
180        bool in_syscall = this->thread->inSyscall;
181        this->thread->inSyscall = true;
182
183        for (int i = 0; i < _numDestMiscRegs; i++)
184            this->cpu->setMiscReg(
185                _destMiscRegIdx[i], _destMiscRegVal[i], this->threadNumber);
186
187        this->thread->inSyscall = in_syscall;
188    }
189
190    void forwardOldRegs()
191    {
192
193        for (int idx = 0; idx < this->numDestRegs(); idx++) {
194            PhysRegIndex prev_phys_reg = this->prevDestRegIdx(idx);
195            TheISA::RegIndex original_dest_reg = this->staticInst->destRegIdx(idx);
196            if (original_dest_reg <  TheISA::FP_Base_DepTag)
197                this->setIntRegOperand(this->staticInst.get(), idx, this->cpu->readIntReg(prev_phys_reg));
198            else if (original_dest_reg < TheISA::Ctrl_Base_DepTag)
199                this->setFloatRegOperandBits(this->staticInst.get(), idx, this->cpu->readFloatRegBits(prev_phys_reg));
200        }
201    }
202#if FULL_SYSTEM
203    /** Calls hardware return from error interrupt. */
204    Fault hwrei();
205    /** Traps to handle specified fault. */
206    void trap(Fault fault);
207    bool simPalCheck(int palFunc);
208#endif
209
210    /** Emulates a syscall. */
211    void syscall(int64_t callnum);
212
213  public:
214
215    // The register accessor methods provide the index of the
216    // instruction's operand (e.g., 0 or 1), not the architectural
217    // register index, to simplify the implementation of register
218    // renaming.  We find the architectural register index by indexing
219    // into the instruction's own operand index table.  Note that a
220    // raw pointer to the StaticInst is provided instead of a
221    // ref-counted StaticInstPtr to redice overhead.  This is fine as
222    // long as these methods don't copy the pointer into any long-term
223    // storage (which is pretty hard to imagine they would have reason
224    // to do).
225
226    uint64_t readIntRegOperand(const StaticInst *si, int idx)
227    {
228        return this->cpu->readIntReg(this->_srcRegIdx[idx]);
229    }
230
231    FloatReg readFloatRegOperand(const StaticInst *si, int idx)
232    {
233        return this->cpu->readFloatReg(this->_srcRegIdx[idx]);
234    }
235
236    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
237    {
238        return this->cpu->readFloatRegBits(this->_srcRegIdx[idx]);
239    }
240
241    /** @todo: Make results into arrays so they can handle multiple dest
242     *  registers.
243     */
244    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
245    {
246        this->cpu->setIntReg(this->_destRegIdx[idx], val);
247        BaseDynInst<Impl>::setIntRegOperand(si, idx, val);
248    }
249
250    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
251    {
252        this->cpu->setFloatReg(this->_destRegIdx[idx], val);
253        BaseDynInst<Impl>::setFloatRegOperand(si, idx, val);
254    }
255
256    void setFloatRegOperandBits(const StaticInst *si, int idx,
257                                FloatRegBits val)
258    {
259        this->cpu->setFloatRegBits(this->_destRegIdx[idx], val);
260        BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val);
261    }
262
263#if THE_ISA == MIPS_ISA
264    uint64_t readRegOtherThread(int misc_reg)
265    {
266        panic("MIPS MT not defined for O3 CPU.\n");
267        return 0;
268    }
269
270    void setRegOtherThread(int misc_reg, const TheISA::MiscReg &val)
271    {
272        panic("MIPS MT not defined for O3 CPU.\n");
273    }
274#endif
275
276  public:
277    /** Calculates EA part of a memory instruction. Currently unused,
278     * though it may be useful in the future if we want to split
279     * memory operations into EA calculation and memory access parts.
280     */
281    Fault calcEA()
282    {
283        return this->staticInst->eaCompInst()->execute(this, this->traceData);
284    }
285
286    /** Does the memory access part of a memory instruction. Currently unused,
287     * though it may be useful in the future if we want to split
288     * memory operations into EA calculation and memory access parts.
289     */
290    Fault memAccess()
291    {
292        return this->staticInst->memAccInst()->execute(this, this->traceData);
293    }
294};
295
296#endif // __CPU_O3_ALPHA_DYN_INST_HH__
297
298