ceb3cbe516cc0e8572537e65dd6fbc574edf01da
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::initiateAcc()
231 // @todo: Pretty convoluted way to avoid squashing from happening
232 // when using the TC during an instruction's execution
233 // (specifically for instructions that have side-effects that use
234 // the TC). Fix this.
235 bool in_syscall
= this->thread
->inSyscall
;
236 this->thread
->inSyscall
= true;
238 this->fault
= this->staticInst
->initiateAcc(this, this->traceData
);
240 this->thread
->inSyscall
= in_syscall
;
247 InOrderDynInst::completeAcc(Packet
*pkt
)
249 this->fault
= this->staticInst
->completeAcc(pkt
, this, this->traceData
);
254 InstStage
*InOrderDynInst::addStage()
256 this->currentInstStage
= new InstStage(this, nextInstStageNum
++);
257 instStageList
.push_back( this->currentInstStage
);
258 return this->currentInstStage
;
261 InstStage
*InOrderDynInst::addStage(int stage_num
)
263 nextInstStageNum
= stage_num
;
264 return InOrderDynInst::addStage();
267 void InOrderDynInst::deleteStages() {
268 std::list
<InstStage
*>::iterator list_it
= instStageList
.begin();
269 std::list
<InstStage
*>::iterator list_end
= instStageList
.end();
271 while(list_it
!= list_end
) {
278 InOrderDynInst::calcEA()
280 return staticInst
->eaCompInst()->execute(this, this->traceData
);
284 InOrderDynInst::memAccess()
286 //return staticInst->memAccInst()->execute(this, this->traceData);
287 return initiateAcc( );
291 InOrderDynInst::syscall(int64_t callnum
)
293 cpu
->syscall(callnum
, this->threadNumber
);
297 InOrderDynInst::prefetch(Addr addr
, unsigned flags
)
299 panic("Prefetch Unimplemented\n");
303 InOrderDynInst::writeHint(Addr addr
, int size
, unsigned flags
)
305 panic("Write-Hint Unimplemented\n");
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
].fp
= 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
)
389 return instSrc
[idx
].fp
;
393 /** Reads a FP register as a integer. */
395 InOrderDynInst::readFloatRegOperandBits(const StaticInst
*si
, int idx
, int width
)
397 return instSrc
[idx
].integer
;
400 /** Reads a miscellaneous register. */
402 InOrderDynInst::readMiscReg(int misc_reg
)
404 return this->cpu
->readMiscReg(misc_reg
, threadNumber
);
407 /** Reads a misc. register, including any side-effects the read
408 * might have as defined by the architecture.
411 InOrderDynInst::readMiscRegNoEffect(int misc_reg
)
413 return this->cpu
->readMiscRegNoEffect(misc_reg
, threadNumber
);
416 /** Reads a miscellaneous register. */
418 InOrderDynInst::readMiscRegOperandNoEffect(const StaticInst
*si
, int idx
)
420 int reg
= si
->srcRegIdx(idx
) - TheISA::Ctrl_Base_DepTag
;
421 return cpu
->readMiscRegNoEffect(reg
, this->threadNumber
);
424 /** Reads a misc. register, including any side-effects the read
425 * might have as defined by the architecture.
428 InOrderDynInst::readMiscRegOperand(const StaticInst
*si
, int idx
)
430 int reg
= si
->srcRegIdx(idx
) - TheISA::Ctrl_Base_DepTag
;
431 return this->cpu
->readMiscReg(reg
, this->threadNumber
);
434 /** Sets a misc. register. */
436 InOrderDynInst::setMiscRegOperandNoEffect(const StaticInst
* si
, int idx
, const MiscReg
&val
)
438 instResult
[si
->destRegIdx(idx
)].val
.integer
= val
;
439 instResult
[si
->destRegIdx(idx
)].tick
= curTick
;
441 this->cpu
->setMiscRegNoEffect(
442 si
->destRegIdx(idx
) - TheISA::Ctrl_Base_DepTag
,
443 val
, this->threadNumber
);
446 /** Sets a misc. register, including any side-effects the write
447 * might have as defined by the architecture.
450 InOrderDynInst::setMiscRegOperand(const StaticInst
*si
, int idx
,
453 instResult
[si
->destRegIdx(idx
)].val
.integer
= val
;
454 instResult
[si
->destRegIdx(idx
)].tick
= curTick
;
456 this->cpu
->setMiscReg(
457 si
->destRegIdx(idx
) - TheISA::Ctrl_Base_DepTag
,
458 val
, this->threadNumber
);
462 InOrderDynInst::readRegOtherThread(unsigned reg_idx
, int tid
)
465 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
468 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
469 return this->cpu
->readIntReg(reg_idx
, tid
);
470 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
471 reg_idx
-= FP_Base_DepTag
;
472 return this->cpu
->readFloatRegBits(reg_idx
, tid
);
474 reg_idx
-= Ctrl_Base_DepTag
;
475 return this->cpu
->readMiscReg(reg_idx
, tid
); // Misc. Register File
479 /** Sets a Integer register. */
481 InOrderDynInst::setIntRegOperand(const StaticInst
*si
, int idx
, IntReg val
)
483 instResult
[idx
].val
.integer
= val
;
484 instResult
[idx
].tick
= curTick
;
487 /** Sets a FP register. */
489 InOrderDynInst::setFloatRegOperand(const StaticInst
*si
, int idx
, FloatReg val
, int width
)
492 instResult
[idx
].val
.fp
= val
;
493 else if (width
== 64)
494 instResult
[idx
].val
.dbl
= val
;
496 panic("Unsupported Floating Point Width!");
498 instResult
[idx
].tick
= curTick
;
501 /** Sets a FP register as a integer. */
503 InOrderDynInst::setFloatRegOperandBits(const StaticInst
*si
, int idx
,
504 FloatRegBits val
, int width
)
506 instResult
[idx
].val
.integer
= val
;
507 instResult
[idx
].tick
= curTick
;
510 /** Sets a misc. register. */
511 /* Alter this when wanting to *speculate* on Miscellaneous registers */
513 InOrderDynInst::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
)
515 this->cpu
->setMiscRegNoEffect(misc_reg
, val
, threadNumber
);
518 /** Sets a misc. register, including any side-effects the write
519 * might have as defined by the architecture.
521 /* Alter this if/when wanting to *speculate* on Miscellaneous registers */
523 InOrderDynInst::setMiscReg(int misc_reg
, const MiscReg
&val
)
525 this->cpu
->setMiscReg(misc_reg
, val
, threadNumber
);
529 InOrderDynInst::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
, int tid
)
532 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
535 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
536 this->cpu
->setIntReg(reg_idx
, val
, tid
);
537 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
538 reg_idx
-= FP_Base_DepTag
;
539 this->cpu
->setFloatRegBits(reg_idx
, val
, tid
);
541 reg_idx
-= Ctrl_Base_DepTag
;
542 this->cpu
->setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
547 InOrderDynInst::deallocateContext(int thread_num
)
549 this->cpu
->deallocateContext(thread_num
);
553 InOrderDynInst::enableVirtProcElement(unsigned vpe
)
555 this->cpu
->enableVirtProcElement(vpe
);
559 InOrderDynInst::disableVirtProcElement(unsigned vpe
)
561 this->cpu
->disableVirtProcElement(threadNumber
, vpe
);
565 InOrderDynInst::enableMultiThreading(unsigned vpe
)
567 this->cpu
->enableMultiThreading(vpe
);
571 InOrderDynInst::disableMultiThreading(unsigned vpe
)
573 this->cpu
->disableMultiThreading(threadNumber
, vpe
);
577 InOrderDynInst::setThreadRescheduleCondition(uint32_t cond
)
579 this->cpu
->setThreadRescheduleCondition(cond
);
584 InOrderDynInst::read(Addr addr
, T
&data
, unsigned flags
)
586 return cpu
->read(this);
589 #ifndef DOXYGEN_SHOULD_SKIP_THIS
593 InOrderDynInst::read(Addr addr
, uint64_t &data
, unsigned flags
);
597 InOrderDynInst::read(Addr addr
, uint32_t &data
, unsigned flags
);
601 InOrderDynInst::read(Addr addr
, uint16_t &data
, unsigned flags
);
605 InOrderDynInst::read(Addr addr
, uint8_t &data
, unsigned flags
);
607 #endif //DOXYGEN_SHOULD_SKIP_THIS
611 InOrderDynInst::read(Addr addr
, double &data
, unsigned flags
)
613 return read(addr
, *(uint64_t*)&data
, flags
);
618 InOrderDynInst::read(Addr addr
, float &data
, unsigned flags
)
620 return read(addr
, *(uint32_t*)&data
, flags
);
625 InOrderDynInst::read(Addr addr
, int32_t &data
, unsigned flags
)
627 return read(addr
, (uint32_t&)data
, flags
);
632 InOrderDynInst::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
634 //memcpy(memData, gtoh(data), sizeof(T));
637 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting store data to %#x.\n",
638 threadNumber
, seqNum
, memData
);
639 return cpu
->write(this);
642 #ifndef DOXYGEN_SHOULD_SKIP_THIS
645 InOrderDynInst::write(uint64_t data
, Addr addr
,
646 unsigned flags
, uint64_t *res
);
650 InOrderDynInst::write(uint32_t data
, Addr addr
,
651 unsigned flags
, uint64_t *res
);
655 InOrderDynInst::write(uint16_t data
, Addr addr
,
656 unsigned flags
, uint64_t *res
);
660 InOrderDynInst::write(uint8_t data
, Addr addr
,
661 unsigned flags
, uint64_t *res
);
663 #endif //DOXYGEN_SHOULD_SKIP_THIS
667 InOrderDynInst::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
669 return write(*(uint64_t*)&data
, addr
, flags
, res
);
674 InOrderDynInst::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
676 return write(*(uint32_t*)&data
, addr
, flags
, res
);
682 InOrderDynInst::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
684 return write((uint32_t)data
, addr
, flags
, res
);
689 InOrderDynInst::dump()
691 cprintf("T%d : %#08d `", threadNumber
, PC
);
692 cout
<< staticInst
->disassemble(PC
);
697 InOrderDynInst::dump(std::string
&outstring
)
699 std::ostringstream s
;
700 s
<< "T" << threadNumber
<< " : 0x" << PC
<< " "
701 << staticInst
->disassemble(PC
);
710 #include "base/hashmap.hh"
712 unsigned int MyHashFunc(const InOrderDynInst
*addr
)
714 unsigned a
= (unsigned)addr
;
715 unsigned hash
= (((a
>> 14) ^ ((a
>> 2) & 0xffff))) & 0x7FFFFFFF;
720 typedef m5::hash_map
<const InOrderDynInst
*, const InOrderDynInst
*, MyHashFunc
>