9355a9f6f23a2eaf157d1ee9c53e7a30c21477e1
2 * Copyright (c) 2007 MIPS Technologies, Inc.
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.
28 * Authors: Korey Sewell
37 #include "base/cprintf.hh"
38 #include "base/trace.hh"
40 #include "arch/faults.hh"
41 #include "cpu/exetrace.hh"
42 #include "mem/request.hh"
44 #include "cpu/inorder/inorder_dyn_inst.hh"
45 #include "cpu/inorder/cpu.hh"
48 using namespace TheISA
;
49 using namespace ThePipeline
;
51 InOrderDynInst::InOrderDynInst(TheISA::ExtMachInst machInst
, Addr inst_PC
,
52 Addr pred_PC
, InstSeqNum seq_num
,
54 : staticInst(machInst
, inst_PC
), traceData(NULL
), cpu(cpu
)
59 nextPC
= PC
+ sizeof(MachInst
);
60 nextNPC
= nextPC
+ sizeof(MachInst
);
66 InOrderDynInst::InOrderDynInst(InOrderCPU
*cpu
,
67 InOrderThreadState
*state
,
70 : traceData(NULL
), cpu(cpu
)
78 InOrderDynInst::InOrderDynInst(StaticInstPtr
&_staticInst
)
79 : seqNum(0), staticInst(_staticInst
), traceData(NULL
)
84 InOrderDynInst::InOrderDynInst()
85 : seqNum(0), traceData(NULL
), cpu(cpu
)
90 int InOrderDynInst::instcount
= 0;
94 InOrderDynInst::setMachInst(ExtMachInst machInst
)
96 staticInst
= StaticInst::decode(machInst
, PC
);
98 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
99 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
102 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
103 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
104 this->_readySrcRegIdx
[i
] = 0;
109 InOrderDynInst::initVars()
118 nextInstStageNum
= 0;
120 for(int i
= 0; i
< MaxInstDestRegs
; i
++)
121 instResult
[i
].val
.integer
= 0;
125 memAddrReady
= false;
129 predictTaken
= false;
130 procDelaySlotOnMispred
= false;
135 // Also make this a parameter, or perhaps get it from xc or cpu.
140 // Initialize the fault to be NoFault.
143 // Make sure to have the renamed register entries set to the same
144 // as the normal register entries. It will allow the IQ to work
145 // without any modifications.
146 if (this->staticInst
) {
147 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
148 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
151 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
152 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
153 this->_readySrcRegIdx
[i
] = 0;
157 // Update Instruction Count for this instruction
159 if (instcount
> 500) {
160 fatal("Number of Active Instructions in CPU is too high. "
161 "(Not Dereferencing Ptrs. Correctly?)\n");
166 DPRINTF(InOrderDynInst
, "DynInst: [tid:%i] [sn:%lli] Instruction created. (active insts: %i)\n",
167 threadNumber
, seqNum
, instcount
);
171 InOrderDynInst::~InOrderDynInst()
187 DPRINTF(InOrderDynInst
, "DynInst: [tid:%i] [sn:%lli] Instruction destroyed. (active insts: %i)\n",
188 threadNumber
, seqNum
, instcount
);
192 InOrderDynInst::setStaticInst(StaticInstPtr
&static_inst
)
194 this->staticInst
= static_inst
;
196 // Make sure to have the renamed register entries set to the same
197 // as the normal register entries. It will allow the IQ to work
198 // without any modifications.
199 if (this->staticInst
) {
200 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
201 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
204 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
205 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
206 this->_readySrcRegIdx
[i
] = 0;
212 InOrderDynInst::execute()
214 // @todo: Pretty convoluted way to avoid squashing from happening
215 // when using the TC during an instruction's execution
216 // (specifically for instructions that have side-effects that use
217 // the TC). Fix this.
218 bool in_syscall
= this->thread
->inSyscall
;
219 this->thread
->inSyscall
= true;
221 this->fault
= this->staticInst
->execute(this, this->traceData
);
223 this->thread
->inSyscall
= in_syscall
;
229 InOrderDynInst::calcEA()
231 this->fault
= this->staticInst
->eaComp(this, this->traceData
);
236 InOrderDynInst::initiateAcc()
238 // @todo: Pretty convoluted way to avoid squashing from happening
239 // when using the TC during an instruction's execution
240 // (specifically for instructions that have side-effects that use
241 // the TC). Fix this.
242 bool in_syscall
= this->thread
->inSyscall
;
243 this->thread
->inSyscall
= true;
245 this->fault
= this->staticInst
->initiateAcc(this, this->traceData
);
247 this->thread
->inSyscall
= in_syscall
;
254 InOrderDynInst::completeAcc(Packet
*pkt
)
256 this->fault
= this->staticInst
->completeAcc(pkt
, this, this->traceData
);
261 InstStage
*InOrderDynInst::addStage()
263 this->currentInstStage
= new InstStage(this, nextInstStageNum
++);
264 instStageList
.push_back( this->currentInstStage
);
265 return this->currentInstStage
;
268 InstStage
*InOrderDynInst::addStage(int stage_num
)
270 nextInstStageNum
= stage_num
;
271 return InOrderDynInst::addStage();
274 void InOrderDynInst::deleteStages() {
275 std::list
<InstStage
*>::iterator list_it
= instStageList
.begin();
276 std::list
<InstStage
*>::iterator list_end
= instStageList
.end();
278 while(list_it
!= list_end
) {
285 InOrderDynInst::memAccess()
287 return initiateAcc();
291 InOrderDynInst::syscall(int64_t callnum
)
293 cpu
->syscall(callnum
, this->threadNumber
);
297 InOrderDynInst::prefetch(Addr addr
, unsigned flags
)
303 InOrderDynInst::writeHint(Addr addr
, int size
, unsigned flags
)
305 cpu
->writeHint(this);
309 * @todo Need to find a way to get the cache block size here.
312 InOrderDynInst::copySrcTranslate(Addr src
)
314 // Not currently supported.
319 * @todo Need to find a way to get the cache block size here.
322 InOrderDynInst::copy(Addr dest
)
324 // Not currently supported.
329 InOrderDynInst::releaseReq(ResourceRequest
* req
)
331 std::list
<ResourceRequest
*>::iterator list_it
= reqList
.begin();
332 std::list
<ResourceRequest
*>::iterator list_end
= reqList
.end();
334 while(list_it
!= list_end
) {
335 if((*list_it
)->getResIdx() == req
->getResIdx() &&
336 (*list_it
)->getSlot() == req
->getSlot()) {
337 DPRINTF(InOrderDynInst
, "[tid:%u]: [sn:%i] Done with request to %s.\n",
338 threadNumber
, seqNum
, req
->res
->name());
339 reqList
.erase(list_it
);
345 panic("Releasing Res. Request That Isnt There!\n");
348 /** Records an integer source register being set to a value. */
350 InOrderDynInst::setIntSrc(int idx
, uint64_t val
)
352 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Source Value %i being set to %#x.\n",
353 threadNumber
, seqNum
, idx
, val
);
354 instSrc
[idx
].integer
= val
;
357 /** Records an fp register being set to a value. */
359 InOrderDynInst::setFloatSrc(int idx
, FloatReg val
, int width
)
362 instSrc
[idx
].dbl
= val
;
363 else if (width
== 64)
364 instSrc
[idx
].dbl
= val
;
366 panic("Unsupported width!");
369 /** Records an fp register being set to an integer value. */
371 InOrderDynInst::setFloatRegBitsSrc(int idx
, uint64_t val
)
373 instSrc
[idx
].integer
= val
;
376 /** Reads a integer register. */
378 InOrderDynInst::readIntRegOperand(const StaticInst
*si
, int idx
, unsigned tid
)
380 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Source Value %i read as %#x.\n",
381 threadNumber
, seqNum
, idx
, instSrc
[idx
].integer
);
382 return instSrc
[idx
].integer
;
385 /** Reads a FP register. */
387 InOrderDynInst::readFloatRegOperand(const StaticInst
*si
, int idx
, int width
)
390 return (float)instSrc
[idx
].dbl
;
391 else if (width
== 64)
392 return instSrc
[idx
].dbl
;
394 panic("Unsupported Floating Point Width!");
400 /** Reads a FP register as a integer. */
402 InOrderDynInst::readFloatRegOperandBits(const StaticInst
*si
, int idx
, int width
)
404 return instSrc
[idx
].integer
;
407 /** Reads a miscellaneous register. */
409 InOrderDynInst::readMiscReg(int misc_reg
)
411 return this->cpu
->readMiscReg(misc_reg
, threadNumber
);
414 /** Reads a misc. register, including any side-effects the read
415 * might have as defined by the architecture.
418 InOrderDynInst::readMiscRegNoEffect(int misc_reg
)
420 return this->cpu
->readMiscRegNoEffect(misc_reg
, threadNumber
);
423 /** Reads a miscellaneous register. */
425 InOrderDynInst::readMiscRegOperandNoEffect(const StaticInst
*si
, int idx
)
427 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Misc. Reg Source Value %i"
428 " read as %#x.\n", threadNumber
, seqNum
, idx
,
429 instSrc
[idx
].integer
);
430 return instSrc
[idx
].integer
;
433 /** Reads a misc. register, including any side-effects the read
434 * might have as defined by the architecture.
437 InOrderDynInst::readMiscRegOperand(const StaticInst
*si
, int idx
)
439 // For In-Order, the side-effect of reading a register happens
440 // when explicitly executing a "ReadSrc" command. This simply returns
442 return readMiscRegOperandNoEffect(si
, idx
);
445 /** Sets a misc. register. */
447 InOrderDynInst::setMiscRegOperandNoEffect(const StaticInst
* si
, int idx
,
450 instResult
[idx
].type
= Integer
;
451 instResult
[idx
].val
.integer
= val
;
452 instResult
[idx
].tick
= curTick
;
454 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting Misc Reg. Operand %i "
455 "being set to %#x.\n", threadNumber
, seqNum
, idx
, val
);
458 /** Sets a misc. register, including any side-effects the write
459 * might have as defined by the architecture.
462 InOrderDynInst::setMiscRegOperand(const StaticInst
*si
, int idx
,
465 // For In-Order, the side-effect of setting a register happens
466 // when explicitly writing back the register value. This
467 // simply maintains the operand value.
468 setMiscRegOperandNoEffect(si
, idx
, val
);
472 InOrderDynInst::readRegOtherThread(unsigned reg_idx
, int tid
)
475 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
478 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
479 return this->cpu
->readIntReg(reg_idx
, tid
);
480 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
481 reg_idx
-= FP_Base_DepTag
;
482 return this->cpu
->readFloatRegBits(reg_idx
, tid
);
484 reg_idx
-= Ctrl_Base_DepTag
;
485 return this->cpu
->readMiscReg(reg_idx
, tid
); // Misc. Register File
489 /** Sets a Integer register. */
491 InOrderDynInst::setIntRegOperand(const StaticInst
*si
, int idx
, IntReg val
)
493 instResult
[idx
].type
= Integer
;
494 instResult
[idx
].val
.integer
= val
;
495 instResult
[idx
].tick
= curTick
;
498 /** Sets a FP register. */
500 InOrderDynInst::setFloatRegOperand(const StaticInst
*si
, int idx
, FloatReg val
, int width
)
503 instResult
[idx
].val
.dbl
= (float)val
;
504 instResult
[idx
].type
= Float
;
505 } else if (width
== 64) {
506 instResult
[idx
].val
.dbl
= val
;
507 instResult
[idx
].type
= Double
;
509 panic("Unsupported Floating Point Width!");
512 instResult
[idx
].tick
= curTick
;
515 /** Sets a FP register as a integer. */
517 InOrderDynInst::setFloatRegOperandBits(const StaticInst
*si
, int idx
,
518 FloatRegBits val
, int width
)
521 instResult
[idx
].type
= Float
;
522 else if (width
== 64)
523 instResult
[idx
].type
= Double
;
525 instResult
[idx
].val
.integer
= val
;
526 instResult
[idx
].tick
= curTick
;
529 /** Sets a misc. register. */
530 /* Alter this when wanting to *speculate* on Miscellaneous registers */
532 InOrderDynInst::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
)
534 this->cpu
->setMiscRegNoEffect(misc_reg
, val
, threadNumber
);
537 /** Sets a misc. register, including any side-effects the write
538 * might have as defined by the architecture.
540 /* Alter this if/when wanting to *speculate* on Miscellaneous registers */
542 InOrderDynInst::setMiscReg(int misc_reg
, const MiscReg
&val
)
544 this->cpu
->setMiscReg(misc_reg
, val
, threadNumber
);
548 InOrderDynInst::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
, int tid
)
551 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
554 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
555 this->cpu
->setIntReg(reg_idx
, val
, tid
);
556 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
557 reg_idx
-= FP_Base_DepTag
;
558 this->cpu
->setFloatRegBits(reg_idx
, val
, tid
);
560 reg_idx
-= Ctrl_Base_DepTag
;
561 this->cpu
->setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
566 InOrderDynInst::deallocateContext(int thread_num
)
568 this->cpu
->deallocateContext(thread_num
);
572 InOrderDynInst::enableVirtProcElement(unsigned vpe
)
574 this->cpu
->enableVirtProcElement(vpe
);
578 InOrderDynInst::disableVirtProcElement(unsigned vpe
)
580 this->cpu
->disableVirtProcElement(threadNumber
, vpe
);
584 InOrderDynInst::enableMultiThreading(unsigned vpe
)
586 this->cpu
->enableMultiThreading(vpe
);
590 InOrderDynInst::disableMultiThreading(unsigned vpe
)
592 this->cpu
->disableMultiThreading(threadNumber
, vpe
);
597 InOrderDynInst::read(Addr addr
, T
&data
, unsigned flags
)
599 return cpu
->read(this);
602 #ifndef DOXYGEN_SHOULD_SKIP_THIS
606 InOrderDynInst::read(Addr addr
, uint64_t &data
, unsigned flags
);
610 InOrderDynInst::read(Addr addr
, uint32_t &data
, unsigned flags
);
614 InOrderDynInst::read(Addr addr
, uint16_t &data
, unsigned flags
);
618 InOrderDynInst::read(Addr addr
, uint8_t &data
, unsigned flags
);
620 #endif //DOXYGEN_SHOULD_SKIP_THIS
624 InOrderDynInst::read(Addr addr
, double &data
, unsigned flags
)
626 return read(addr
, *(uint64_t*)&data
, flags
);
631 InOrderDynInst::read(Addr addr
, float &data
, unsigned flags
)
633 return read(addr
, *(uint32_t*)&data
, flags
);
638 InOrderDynInst::read(Addr addr
, int32_t &data
, unsigned flags
)
640 return read(addr
, (uint32_t&)data
, flags
);
645 InOrderDynInst::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
647 //memcpy(memData, gtoh(data), sizeof(T));
650 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting store data to %#x.\n",
651 threadNumber
, seqNum
, memData
);
652 return cpu
->write(this);
655 #ifndef DOXYGEN_SHOULD_SKIP_THIS
658 InOrderDynInst::write(uint64_t data
, Addr addr
,
659 unsigned flags
, uint64_t *res
);
663 InOrderDynInst::write(uint32_t data
, Addr addr
,
664 unsigned flags
, uint64_t *res
);
668 InOrderDynInst::write(uint16_t data
, Addr addr
,
669 unsigned flags
, uint64_t *res
);
673 InOrderDynInst::write(uint8_t data
, Addr addr
,
674 unsigned flags
, uint64_t *res
);
676 #endif //DOXYGEN_SHOULD_SKIP_THIS
680 InOrderDynInst::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
682 return write(*(uint64_t*)&data
, addr
, flags
, res
);
687 InOrderDynInst::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
689 return write(*(uint32_t*)&data
, addr
, flags
, res
);
695 InOrderDynInst::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
697 return write((uint32_t)data
, addr
, flags
, res
);
702 InOrderDynInst::dump()
704 cprintf("T%d : %#08d `", threadNumber
, PC
);
705 cout
<< staticInst
->disassemble(PC
);
710 InOrderDynInst::dump(std::string
&outstring
)
712 std::ostringstream s
;
713 s
<< "T" << threadNumber
<< " : 0x" << PC
<< " "
714 << staticInst
->disassemble(PC
);
723 #include "base/hashmap.hh"
725 unsigned int MyHashFunc(const InOrderDynInst
*addr
)
727 unsigned a
= (unsigned)addr
;
728 unsigned hash
= (((a
>> 14) ^ ((a
>> 2) & 0xffff))) & 0x7FFFFFFF;
733 typedef m5::hash_map
<const InOrderDynInst
*, const InOrderDynInst
*, MyHashFunc
>