2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __CPU_O3_DYN_INST_HH__
32 #define __CPU_O3_DYN_INST_HH__
34 #include "arch/isa_traits.hh"
35 #include "cpu/base_dyn_inst.hh"
36 #include "cpu/inst_seq.hh"
37 #include "cpu/o3/cpu.hh"
38 #include "cpu/o3/isa_specific.hh"
43 * Mostly implementation & ISA specific AlphaDynInst. As with most
44 * other classes in the new CPU model, it is templated on the Impl to
45 * allow for passing in of all types, such as the CPU type and the ISA
46 * type. The AlphaDynInst serves as the primary interface to the CPU
47 * for instructions that are executing.
50 class BaseO3DynInst : public BaseDynInst<Impl>
53 /** Typedef for the CPU. */
54 typedef typename Impl::O3CPU O3CPU;
56 /** Binary machine instruction type. */
57 typedef TheISA::MachInst MachInst;
58 /** Extended machine instruction type. */
59 typedef TheISA::ExtMachInst ExtMachInst;
60 /** Logical register index type. */
61 typedef TheISA::RegIndex RegIndex;
62 /** Integer register index type. */
63 typedef TheISA::IntReg IntReg;
64 typedef TheISA::FloatReg FloatReg;
65 typedef TheISA::FloatRegBits FloatRegBits;
66 /** Misc register index type. */
67 typedef TheISA::MiscReg MiscReg;
70 MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
71 MaxInstDestRegs = TheISA::MaxInstDestRegs, //< Max dest regs
75 /** BaseDynInst constructor given a binary instruction. */
76 BaseO3DynInst(StaticInstPtr staticInst, Addr PC, Addr NPC, Addr microPC,
77 Addr Pred_PC, Addr Pred_NPC, Addr Pred_MicroPC,
78 InstSeqNum seq_num, O3CPU *cpu);
80 /** BaseDynInst constructor given a binary instruction. */
81 BaseO3DynInst(ExtMachInst inst, Addr PC, Addr NPC, Addr microPC,
82 Addr Pred_PC, Addr Pred_NPC, Addr Pred_MicroPC,
83 InstSeqNum seq_num, O3CPU *cpu);
85 /** BaseDynInst constructor given a static inst pointer. */
86 BaseO3DynInst(StaticInstPtr &_staticInst);
88 /** Executes the instruction.*/
91 /** Initiates the access. Only valid for memory operations. */
94 /** Completes the access. Only valid for memory operations. */
95 Fault completeAcc(PacketPtr pkt);
98 /** Initializes variables. */
102 /** Reads a miscellaneous register. */
103 MiscReg readMiscRegNoEffect(int misc_reg)
105 return this->cpu->readMiscRegNoEffect(misc_reg, this->threadNumber);
108 /** Reads a misc. register, including any side-effects the read
109 * might have as defined by the architecture.
111 MiscReg readMiscReg(int misc_reg)
113 return this->cpu->readMiscReg(misc_reg, this->threadNumber);
116 /** Sets a misc. register. */
117 void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
119 this->instResult.integer = val;
120 return this->cpu->setMiscRegNoEffect(misc_reg, val, this->threadNumber);
123 /** Sets a misc. register, including any side-effects the write
124 * might have as defined by the architecture.
126 void setMiscReg(int misc_reg, const MiscReg &val)
128 return this->cpu->setMiscReg(misc_reg, val,
132 /** Reads a miscellaneous register. */
133 TheISA::MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx)
135 return this->cpu->readMiscRegNoEffect(
136 si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag,
140 /** Reads a misc. register, including any side-effects the read
141 * might have as defined by the architecture.
143 TheISA::MiscReg readMiscRegOperand(const StaticInst *si, int idx)
145 return this->cpu->readMiscReg(
146 si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag,
150 /** Sets a misc. register. */
151 void setMiscRegOperandNoEffect(const StaticInst * si, int idx, const MiscReg &val)
153 this->instResult.integer = val;
154 return this->cpu->setMiscRegNoEffect(
155 si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag,
156 val, this->threadNumber);
159 /** Sets a misc. register, including any side-effects the write
160 * might have as defined by the architecture.
162 void setMiscRegOperand(const StaticInst *si, int idx,
165 return this->cpu->setMiscReg(
166 si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag,
167 val, this->threadNumber);
171 /** Traps to handle specified fault. */
172 void trap(Fault fault);
174 /** Calls a syscall. */
175 void syscall(int64_t callnum);
180 // The register accessor methods provide the index of the
181 // instruction's operand (e.g., 0 or 1), not the architectural
182 // register index, to simplify the implementation of register
183 // renaming. We find the architectural register index by indexing
184 // into the instruction's own operand index table. Note that a
185 // raw pointer to the StaticInst is provided instead of a
186 // ref-counted StaticInstPtr to redice overhead. This is fine as
187 // long as these methods don't copy the pointer into any long-term
188 // storage (which is pretty hard to imagine they would have reason
191 uint64_t readIntRegOperand(const StaticInst *si, int idx)
193 return this->cpu->readIntReg(this->_srcRegIdx[idx]);
196 FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width)
198 return this->cpu->readFloatReg(this->_srcRegIdx[idx], width);
201 FloatReg readFloatRegOperand(const StaticInst *si, int idx)
203 return this->cpu->readFloatReg(this->_srcRegIdx[idx]);
206 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
209 return this->cpu->readFloatRegBits(this->_srcRegIdx[idx], width);
212 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
214 return this->cpu->readFloatRegBits(this->_srcRegIdx[idx]);
217 /** @todo: Make results into arrays so they can handle multiple dest
220 void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
222 this->cpu->setIntReg(this->_destRegIdx[idx], val);
223 BaseDynInst<Impl>::setIntRegOperand(si, idx, val);
226 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
229 this->cpu->setFloatReg(this->_destRegIdx[idx], val, width);
230 BaseDynInst<Impl>::setFloatRegOperand(si, idx, val, width);
233 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
235 this->cpu->setFloatReg(this->_destRegIdx[idx], val);
236 BaseDynInst<Impl>::setFloatRegOperand(si, idx, val);
239 void setFloatRegOperandBits(const StaticInst *si, int idx,
240 FloatRegBits val, int width)
242 this->cpu->setFloatRegBits(this->_destRegIdx[idx], val, width);
243 BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val);
246 void setFloatRegOperandBits(const StaticInst *si, int idx,
249 this->cpu->setFloatRegBits(this->_destRegIdx[idx], val);
250 BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val);
253 #if THE_ISA == MIPS_ISA
254 uint64_t readRegOtherThread(int misc_reg)
256 panic("MIPS MT not defined for O3 CPU.\n");
260 void setRegOtherThread(int misc_reg, const TheISA::MiscReg &val)
262 panic("MIPS MT not defined for O3 CPU.\n");
267 /** Calculates EA part of a memory instruction. Currently unused,
268 * though it may be useful in the future if we want to split
269 * memory operations into EA calculation and memory access parts.
273 return this->staticInst->eaCompInst()->execute(this, this->traceData);
276 /** Does the memory access part of a memory instruction. Currently unused,
277 * though it may be useful in the future if we want to split
278 * memory operations into EA calculation and memory access parts.
282 return this->staticInst->memAccInst()->execute(this, this->traceData);
286 #endif // __CPU_O3_ALPHA_DYN_INST_HH__