dyn_inst.hh revision 5639:67cc7f0427e7
1/* 2 * Copyright (c) 2004-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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. 15 * 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. 27 * 28 * Authors: Kevin Lim 29 */ 30 31#ifndef __CPU_O3_DYN_INST_HH__ 32#define __CPU_O3_DYN_INST_HH__ 33 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" 39 40class Packet; 41 42/** 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. 48 */ 49template <class Impl> 50class BaseO3DynInst : public BaseDynInst<Impl> 51{ 52 public: 53 /** Typedef for the CPU. */ 54 typedef typename Impl::O3CPU O3CPU; 55 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; 68 69 enum { 70 MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs 71 MaxInstDestRegs = TheISA::MaxInstDestRegs, //< Max dest regs 72 }; 73 74 public: 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); 79 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); 84 85 /** BaseDynInst constructor given a static inst pointer. */ 86 BaseO3DynInst(StaticInstPtr &_staticInst); 87 88 /** Executes the instruction.*/ 89 Fault execute(); 90 91 /** Initiates the access. Only valid for memory operations. */ 92 Fault initiateAcc(); 93 94 /** Completes the access. Only valid for memory operations. */ 95 Fault completeAcc(PacketPtr pkt); 96 97 private: 98 /** Initializes variables. */ 99 void initVars(); 100 101 public: 102 /** Reads a miscellaneous register. */ 103 MiscReg readMiscRegNoEffect(int misc_reg) 104 { 105 return this->cpu->readMiscRegNoEffect(misc_reg, this->threadNumber); 106 } 107 108 /** Reads a misc. register, including any side-effects the read 109 * might have as defined by the architecture. 110 */ 111 MiscReg readMiscReg(int misc_reg) 112 { 113 return this->cpu->readMiscReg(misc_reg, this->threadNumber); 114 } 115 116 /** Sets a misc. register. */ 117 void setMiscRegNoEffect(int misc_reg, const MiscReg &val) 118 { 119 this->instResult.integer = val; 120 return this->cpu->setMiscRegNoEffect(misc_reg, val, this->threadNumber); 121 } 122 123 /** Sets a misc. register, including any side-effects the write 124 * might have as defined by the architecture. 125 */ 126 void setMiscReg(int misc_reg, const MiscReg &val) 127 { 128 return this->cpu->setMiscReg(misc_reg, val, 129 this->threadNumber); 130 } 131 132 /** Reads a miscellaneous register. */ 133 TheISA::MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx) 134 { 135 return this->cpu->readMiscRegNoEffect( 136 si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag, 137 this->threadNumber); 138 } 139 140 /** Reads a misc. register, including any side-effects the read 141 * might have as defined by the architecture. 142 */ 143 TheISA::MiscReg readMiscRegOperand(const StaticInst *si, int idx) 144 { 145 return this->cpu->readMiscReg( 146 si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag, 147 this->threadNumber); 148 } 149 150 /** Sets a misc. register. */ 151 void setMiscRegOperandNoEffect(const StaticInst * si, int idx, const MiscReg &val) 152 { 153 this->instResult.integer = val; 154 return this->cpu->setMiscRegNoEffect( 155 si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag, 156 val, this->threadNumber); 157 } 158 159 /** Sets a misc. register, including any side-effects the write 160 * might have as defined by the architecture. 161 */ 162 void setMiscRegOperand(const StaticInst *si, int idx, 163 const MiscReg &val) 164 { 165 return this->cpu->setMiscReg( 166 si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag, 167 val, this->threadNumber); 168 } 169 170#if FULL_SYSTEM 171 /** Traps to handle specified fault. */ 172 void trap(Fault fault); 173 bool simPalCheck(int palFunc); 174#else 175 /** Calls a syscall. */ 176 void syscall(int64_t callnum); 177#endif 178 179 public: 180 181 // The register accessor methods provide the index of the 182 // instruction's operand (e.g., 0 or 1), not the architectural 183 // register index, to simplify the implementation of register 184 // renaming. We find the architectural register index by indexing 185 // into the instruction's own operand index table. Note that a 186 // raw pointer to the StaticInst is provided instead of a 187 // ref-counted StaticInstPtr to redice overhead. This is fine as 188 // long as these methods don't copy the pointer into any long-term 189 // storage (which is pretty hard to imagine they would have reason 190 // to do). 191 192 uint64_t readIntRegOperand(const StaticInst *si, int idx) 193 { 194 return this->cpu->readIntReg(this->_srcRegIdx[idx]); 195 } 196 197 FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width) 198 { 199 return this->cpu->readFloatReg(this->_srcRegIdx[idx], width); 200 } 201 202 FloatReg readFloatRegOperand(const StaticInst *si, int idx) 203 { 204 return this->cpu->readFloatReg(this->_srcRegIdx[idx]); 205 } 206 207 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx, 208 int width) 209 { 210 return this->cpu->readFloatRegBits(this->_srcRegIdx[idx], width); 211 } 212 213 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) 214 { 215 return this->cpu->readFloatRegBits(this->_srcRegIdx[idx]); 216 } 217 218 /** @todo: Make results into arrays so they can handle multiple dest 219 * registers. 220 */ 221 void setIntRegOperand(const StaticInst *si, int idx, uint64_t val) 222 { 223 this->cpu->setIntReg(this->_destRegIdx[idx], val); 224 BaseDynInst<Impl>::setIntRegOperand(si, idx, val); 225 } 226 227 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val, 228 int width) 229 { 230 this->cpu->setFloatReg(this->_destRegIdx[idx], val, width); 231 BaseDynInst<Impl>::setFloatRegOperand(si, idx, val, width); 232 } 233 234 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) 235 { 236 this->cpu->setFloatReg(this->_destRegIdx[idx], val); 237 BaseDynInst<Impl>::setFloatRegOperand(si, idx, val); 238 } 239 240 void setFloatRegOperandBits(const StaticInst *si, int idx, 241 FloatRegBits val, int width) 242 { 243 this->cpu->setFloatRegBits(this->_destRegIdx[idx], val, width); 244 BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val); 245 } 246 247 void setFloatRegOperandBits(const StaticInst *si, int idx, 248 FloatRegBits val) 249 { 250 this->cpu->setFloatRegBits(this->_destRegIdx[idx], val); 251 BaseDynInst<Impl>::setFloatRegOperandBits(si, idx, val); 252 } 253 254#if THE_ISA == MIPS_ISA 255 uint64_t readRegOtherThread(int misc_reg) 256 { 257 panic("MIPS MT not defined for O3 CPU.\n"); 258 return 0; 259 } 260 261 void setRegOtherThread(int misc_reg, const TheISA::MiscReg &val) 262 { 263 panic("MIPS MT not defined for O3 CPU.\n"); 264 } 265#endif 266 267 public: 268 /** Calculates EA 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 calcEA() 273 { 274 return this->staticInst->eaCompInst()->execute(this, this->traceData); 275 } 276 277 /** Does the memory access 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 memAccess() 282 { 283 return this->staticInst->memAccInst()->execute(this, this->traceData); 284 } 285}; 286 287#endif // __CPU_O3_ALPHA_DYN_INST_HH__ 288 289