dyn_inst.hh revision 7783
111723Sar4jc@virginia.edu/*
211723Sar4jc@virginia.edu * Copyright (c) 2010 ARM Limited
311723Sar4jc@virginia.edu * All rights reserved
411723Sar4jc@virginia.edu *
511723Sar4jc@virginia.edu * The license below extends only to copyright in the software and shall
611723Sar4jc@virginia.edu * not be construed as granting a license to any other intellectual
711723Sar4jc@virginia.edu * property including but not limited to intellectual property relating
811723Sar4jc@virginia.edu * to a hardware implementation of the functionality of the software
911723Sar4jc@virginia.edu * licensed hereunder.  You may use the software subject to the license
1011723Sar4jc@virginia.edu * terms below provided that you ensure that this notice is replicated
1111723Sar4jc@virginia.edu * unmodified and in its entirety in all distributions of the software,
1211723Sar4jc@virginia.edu * modified or unmodified, in source code or in binary form.
1311723Sar4jc@virginia.edu *
1411723Sar4jc@virginia.edu * Copyright (c) 2004-2006 The Regents of The University of Michigan
1511723Sar4jc@virginia.edu * All rights reserved.
1611723Sar4jc@virginia.edu *
1711723Sar4jc@virginia.edu * Redistribution and use in source and binary forms, with or without
1811723Sar4jc@virginia.edu * modification, are permitted provided that the following conditions are
1911723Sar4jc@virginia.edu * met: redistributions of source code must retain the above copyright
2011723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer;
2111723Sar4jc@virginia.edu * redistributions in binary form must reproduce the above copyright
2211723Sar4jc@virginia.edu * notice, this list of conditions and the following disclaimer in the
2311723Sar4jc@virginia.edu * documentation and/or other materials provided with the distribution;
2411723Sar4jc@virginia.edu * neither the name of the copyright holders nor the names of its
2511723Sar4jc@virginia.edu * contributors may be used to endorse or promote products derived from
2611723Sar4jc@virginia.edu * this software without specific prior written permission.
2711723Sar4jc@virginia.edu *
2811723Sar4jc@virginia.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2911723Sar4jc@virginia.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3011723Sar4jc@virginia.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3111723Sar4jc@virginia.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3211723Sar4jc@virginia.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3311723Sar4jc@virginia.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3411723Sar4jc@virginia.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3511723Sar4jc@virginia.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3611723Sar4jc@virginia.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3711723Sar4jc@virginia.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3811723Sar4jc@virginia.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3911723Sar4jc@virginia.edu *
4011723Sar4jc@virginia.edu * Authors: Kevin Lim
4111723Sar4jc@virginia.edu */
4211723Sar4jc@virginia.edu
4311723Sar4jc@virginia.edu#ifndef __CPU_O3_DYN_INST_HH__
4411723Sar4jc@virginia.edu#define __CPU_O3_DYN_INST_HH__
4511723Sar4jc@virginia.edu
4611723Sar4jc@virginia.edu#include "arch/isa_traits.hh"
4711723Sar4jc@virginia.edu#include "config/the_isa.hh"
4811723Sar4jc@virginia.edu#include "cpu/base_dyn_inst.hh"
4911723Sar4jc@virginia.edu#include "cpu/inst_seq.hh"
5011723Sar4jc@virginia.edu#include "cpu/o3/cpu.hh"
5111723Sar4jc@virginia.edu#include "cpu/o3/isa_specific.hh"
5211723Sar4jc@virginia.edu
5311723Sar4jc@virginia.educlass Packet;
5411723Sar4jc@virginia.edu
5511723Sar4jc@virginia.edu/**
5611723Sar4jc@virginia.edu * Mostly implementation & ISA specific AlphaDynInst. As with most
5711723Sar4jc@virginia.edu * other classes in the new CPU model, it is templated on the Impl to
5811723Sar4jc@virginia.edu * allow for passing in of all types, such as the CPU type and the ISA
5911723Sar4jc@virginia.edu * type. The AlphaDynInst serves as the primary interface to the CPU
6011723Sar4jc@virginia.edu * for instructions that are executing.
6111723Sar4jc@virginia.edu */
6211723Sar4jc@virginia.edutemplate <class Impl>
6311723Sar4jc@virginia.educlass BaseO3DynInst : public BaseDynInst<Impl>
6411723Sar4jc@virginia.edu{
6511723Sar4jc@virginia.edu  public:
6611723Sar4jc@virginia.edu    /** Typedef for the CPU. */
6711723Sar4jc@virginia.edu    typedef typename Impl::O3CPU O3CPU;
6811723Sar4jc@virginia.edu
6911723Sar4jc@virginia.edu    /** Binary machine instruction type. */
7011723Sar4jc@virginia.edu    typedef TheISA::MachInst MachInst;
7111723Sar4jc@virginia.edu    /** Extended machine instruction type. */
7211723Sar4jc@virginia.edu    typedef TheISA::ExtMachInst ExtMachInst;
7311723Sar4jc@virginia.edu    /** Logical register index type. */
7411723Sar4jc@virginia.edu    typedef TheISA::RegIndex RegIndex;
7511723Sar4jc@virginia.edu    /** Integer register index type. */
7611723Sar4jc@virginia.edu    typedef TheISA::IntReg   IntReg;
7711723Sar4jc@virginia.edu    typedef TheISA::FloatReg FloatReg;
7811723Sar4jc@virginia.edu    typedef TheISA::FloatRegBits FloatRegBits;
7911723Sar4jc@virginia.edu    /** Misc register index type. */
8011723Sar4jc@virginia.edu    typedef TheISA::MiscReg  MiscReg;
8111723Sar4jc@virginia.edu
8211723Sar4jc@virginia.edu    enum {
8311723Sar4jc@virginia.edu        MaxInstSrcRegs = TheISA::MaxInstSrcRegs,        //< Max source regs
8411723Sar4jc@virginia.edu        MaxInstDestRegs = TheISA::MaxInstDestRegs,      //< Max dest regs
8511723Sar4jc@virginia.edu    };
8611723Sar4jc@virginia.edu
8711723Sar4jc@virginia.edu  public:
8811723Sar4jc@virginia.edu    /** BaseDynInst constructor given a binary instruction. */
8911723Sar4jc@virginia.edu    BaseO3DynInst(StaticInstPtr staticInst,
9011723Sar4jc@virginia.edu                  TheISA::PCState pc, TheISA::PCState predPC,
9111723Sar4jc@virginia.edu                  InstSeqNum seq_num, O3CPU *cpu);
9211723Sar4jc@virginia.edu
9311723Sar4jc@virginia.edu    /** BaseDynInst constructor given a binary instruction. */
9411723Sar4jc@virginia.edu    BaseO3DynInst(ExtMachInst inst,
9511723Sar4jc@virginia.edu                  TheISA::PCState pc, TheISA::PCState predPC,
9611723Sar4jc@virginia.edu                  InstSeqNum seq_num, O3CPU *cpu);
9711723Sar4jc@virginia.edu
9811723Sar4jc@virginia.edu    /** BaseDynInst constructor given a static inst pointer. */
9911723Sar4jc@virginia.edu    BaseO3DynInst(StaticInstPtr &_staticInst);
10011723Sar4jc@virginia.edu
10111723Sar4jc@virginia.edu    /** Executes the instruction.*/
10211723Sar4jc@virginia.edu    Fault execute();
10311723Sar4jc@virginia.edu
10411723Sar4jc@virginia.edu    /** Initiates the access.  Only valid for memory operations. */
10511723Sar4jc@virginia.edu    Fault initiateAcc();
10611723Sar4jc@virginia.edu
10711723Sar4jc@virginia.edu    /** Completes the access.  Only valid for memory operations. */
10811723Sar4jc@virginia.edu    Fault completeAcc(PacketPtr pkt);
10911723Sar4jc@virginia.edu
11011723Sar4jc@virginia.edu  private:
11111723Sar4jc@virginia.edu    /** Initializes variables. */
11211723Sar4jc@virginia.edu    void initVars();
11311723Sar4jc@virginia.edu
11411723Sar4jc@virginia.edu  protected:
11511723Sar4jc@virginia.edu    /** Indexes of the destination misc. registers. They are needed to defer
11611723Sar4jc@virginia.edu     * the write accesses to the misc. registers until the commit stage, when
11711723Sar4jc@virginia.edu     * the instruction is out of its speculative state.
11811723Sar4jc@virginia.edu     */
11911723Sar4jc@virginia.edu    int _destMiscRegIdx[MaxInstDestRegs];
12011723Sar4jc@virginia.edu    /** Values to be written to the destination misc. registers. */
12111723Sar4jc@virginia.edu    MiscReg _destMiscRegVal[MaxInstDestRegs];
122    /** Number of destination misc. registers. */
123    int _numDestMiscRegs;
124
125  public:
126    /** Reads a misc. register, including any side-effects the read
127     * might have as defined by the architecture.
128     */
129    MiscReg readMiscReg(int misc_reg)
130    {
131        return this->cpu->readMiscReg(misc_reg, this->threadNumber);
132    }
133
134    /** Sets a misc. register, including any side-effects the write
135     * might have as defined by the architecture.
136     */
137    void setMiscReg(int misc_reg, const MiscReg &val)
138    {
139        /** Writes to misc. registers are recorded and deferred until the
140         * commit stage, when updateMiscRegs() is called.
141         */
142        _destMiscRegIdx[_numDestMiscRegs] = misc_reg;
143        _destMiscRegVal[_numDestMiscRegs] = val;
144        _numDestMiscRegs++;
145    }
146
147    /** Reads a misc. register, including any side-effects the read
148     * might have as defined by the architecture.
149     */
150    TheISA::MiscReg readMiscRegOperand(const StaticInst *si, int idx)
151    {
152        return this->cpu->readMiscReg(
153                si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag,
154                this->threadNumber);
155    }
156
157    /** Sets a misc. register, including any side-effects the write
158     * might have as defined by the architecture.
159     */
160    void setMiscRegOperand(const StaticInst *si, int idx,
161                                     const MiscReg &val)
162    {
163        int misc_reg = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
164        setMiscReg(misc_reg, val);
165    }
166
167    /** Called at the commit stage to update the misc. registers. */
168    void updateMiscRegs()
169    {
170        // @todo: Pretty convoluted way to avoid squashing from happening when
171        // using the TC during an instruction's execution (specifically for
172        // instructions that have side-effects that use the TC).  Fix this.
173        // See cpu/o3/dyn_inst_impl.hh.
174        bool in_syscall = this->thread->inSyscall;
175        this->thread->inSyscall = true;
176
177        for (int i = 0; i < _numDestMiscRegs; i++)
178            this->cpu->setMiscReg(
179                _destMiscRegIdx[i], _destMiscRegVal[i], this->threadNumber);
180
181        this->thread->inSyscall = in_syscall;
182    }
183
184#if FULL_SYSTEM
185    /** Calls hardware return from error interrupt. */
186    Fault hwrei();
187    /** Traps to handle specified fault. */
188    void trap(Fault fault);
189    bool simPalCheck(int palFunc);
190#else
191    /** Calls a syscall. */
192    void syscall(int64_t callnum);
193#endif
194
195  public:
196
197    // The register accessor methods provide the index of the
198    // instruction's operand (e.g., 0 or 1), not the architectural
199    // register index, to simplify the implementation of register
200    // renaming.  We find the architectural register index by indexing
201    // into the instruction's own operand index table.  Note that a
202    // raw pointer to the StaticInst is provided instead of a
203    // ref-counted StaticInstPtr to redice overhead.  This is fine as
204    // long as these methods don't copy the pointer into any long-term
205    // storage (which is pretty hard to imagine they would have reason
206    // to do).
207
208    uint64_t readIntRegOperand(const StaticInst *si, int idx)
209    {
210        return this->cpu->readIntReg(this->_srcRegIdx[idx]);
211    }
212
213    FloatReg readFloatRegOperand(const StaticInst *si, int idx)
214    {
215        return this->cpu->readFloatReg(this->_srcRegIdx[idx]);
216    }
217
218    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
219    {
220        return this->cpu->readFloatRegBits(this->_srcRegIdx[idx]);
221    }
222
223    /** @todo: Make results into arrays so they can handle multiple dest
224     *  registers.
225     */
226    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
227    {
228        this->cpu->setIntReg(this->_destRegIdx[idx], val);
229        BaseDynInst<Impl>::setIntRegOperand(si, idx, val);
230    }
231
232    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
233    {
234        this->cpu->setFloatReg(this->_destRegIdx[idx], val);
235        BaseDynInst<Impl>::setFloatRegOperand(si, idx, val);
236    }
237
238    void setFloatRegOperandBits(const StaticInst *si, int idx,
239                                FloatRegBits val)
240    {
241        this->cpu->setFloatRegBits(this->_destRegIdx[idx], val);
242        BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val);
243    }
244
245#if THE_ISA == MIPS_ISA
246    uint64_t readRegOtherThread(int misc_reg)
247    {
248        panic("MIPS MT not defined for O3 CPU.\n");
249        return 0;
250    }
251
252    void setRegOtherThread(int misc_reg, const TheISA::MiscReg &val)
253    {
254        panic("MIPS MT not defined for O3 CPU.\n");
255    }
256#endif
257
258  public:
259    /** Calculates EA part of a memory instruction. Currently unused,
260     * though it may be useful in the future if we want to split
261     * memory operations into EA calculation and memory access parts.
262     */
263    Fault calcEA()
264    {
265        return this->staticInst->eaCompInst()->execute(this, this->traceData);
266    }
267
268    /** Does the memory access part of a memory instruction. Currently unused,
269     * though it may be useful in the future if we want to split
270     * memory operations into EA calculation and memory access parts.
271     */
272    Fault memAccess()
273    {
274        return this->staticInst->memAccInst()->execute(this, this->traceData);
275    }
276};
277
278#endif // __CPU_O3_ALPHA_DYN_INST_HH__
279
280