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 "arch/faults.hh"
38 #include "base/cprintf.hh"
39 #include "base/trace.hh"
40 #include "config/the_isa.hh"
41 #include "cpu/exetrace.hh"
42 #include "cpu/inorder/cpu.hh"
43 #include "cpu/inorder/inorder_dyn_inst.hh"
44 #include "mem/request.hh"
47 using namespace TheISA
;
48 using namespace ThePipeline
;
50 InOrderDynInst::InOrderDynInst(TheISA::ExtMachInst machInst
,
51 const TheISA::PCState
&instPC
,
52 const TheISA::PCState
&_predPC
,
53 InstSeqNum seq_num
, InOrderCPU
*cpu
)
54 : staticInst(machInst
, instPC
.instAddr()), traceData(NULL
), cpu(cpu
)
64 InOrderDynInst::InOrderDynInst(InOrderCPU
*cpu
,
65 InOrderThreadState
*state
,
69 : 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
.instAddr());
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()
115 split2ndAccess
= false;
117 splitInstSked
= false;
126 nextInstStageNum
= 0;
128 for(int i
= 0; i
< MaxInstDestRegs
; i
++)
129 instResult
[i
].val
.integer
= 0;
133 memAddrReady
= false;
137 predictTaken
= false;
138 procDelaySlotOnMispred
= false;
143 // Also make this a parameter, or perhaps get it from xc or cpu.
148 // Initialize the fault to be NoFault.
151 // Make sure to have the renamed register entries set to the same
152 // as the normal register entries. It will allow the IQ to work
153 // without any modifications.
154 if (this->staticInst
) {
155 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
156 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
159 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
160 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
161 this->_readySrcRegIdx
[i
] = 0;
165 // Update Instruction Count for this instruction
167 if (instcount
> 100) {
168 fatal("Number of Active Instructions in CPU is too high. "
169 "(Not Dereferencing Ptrs. Correctly?)\n");
174 DPRINTF(InOrderDynInst
, "DynInst: [tid:%i] [sn:%lli] Instruction created."
175 " (active insts: %i)\n", threadNumber
, seqNum
, instcount
);
179 InOrderDynInst::resetInstCount()
185 InOrderDynInst::~InOrderDynInst()
187 if (fetchMemReq
!= 0x0) {
192 if (dataMemReq
!= 0x0) {
202 delete [] splitMemData
;
211 DPRINTF(InOrderDynInst
, "DynInst: [tid:%i] [sn:%lli] Instruction destroyed"
212 " (active insts: %i)\n", threadNumber
, seqNum
, instcount
);
216 InOrderDynInst::setStaticInst(StaticInstPtr
&static_inst
)
218 this->staticInst
= static_inst
;
220 // Make sure to have the renamed register entries set to the same
221 // as the normal register entries. It will allow the IQ to work
222 // without any modifications.
223 if (this->staticInst
) {
224 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
225 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
228 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
229 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
230 this->_readySrcRegIdx
[i
] = 0;
236 InOrderDynInst::execute()
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
->execute(this, this->traceData
);
247 this->thread
->inSyscall
= in_syscall
;
253 InOrderDynInst::calcEA()
255 this->fault
= this->staticInst
->eaComp(this, this->traceData
);
260 InOrderDynInst::initiateAcc()
262 // @todo: Pretty convoluted way to avoid squashing from happening
263 // when using the TC during an instruction's execution
264 // (specifically for instructions that have side-effects that use
265 // the TC). Fix this.
266 bool in_syscall
= this->thread
->inSyscall
;
267 this->thread
->inSyscall
= true;
269 this->fault
= this->staticInst
->initiateAcc(this, this->traceData
);
271 this->thread
->inSyscall
= in_syscall
;
278 InOrderDynInst::completeAcc(Packet
*pkt
)
280 this->fault
= this->staticInst
->completeAcc(pkt
, this, this->traceData
);
285 InstStage
*InOrderDynInst::addStage()
287 this->currentInstStage
= new InstStage(this, nextInstStageNum
++);
288 instStageList
.push_back( this->currentInstStage
);
289 return this->currentInstStage
;
292 InstStage
*InOrderDynInst::addStage(int stage_num
)
294 nextInstStageNum
= stage_num
;
295 return InOrderDynInst::addStage();
298 void InOrderDynInst::deleteStages() {
299 std::list
<InstStage
*>::iterator list_it
= instStageList
.begin();
300 std::list
<InstStage
*>::iterator list_end
= instStageList
.end();
302 while(list_it
!= list_end
) {
309 InOrderDynInst::memAccess()
311 return initiateAcc();
318 InOrderDynInst::hwrei()
320 panic("InOrderDynInst: hwrei: unimplemented\n");
326 InOrderDynInst::trap(Fault fault
)
328 this->cpu
->trap(fault
, this->threadNumber
, this);
333 InOrderDynInst::simPalCheck(int palFunc
)
335 #if THE_ISA != ALPHA_ISA
336 panic("simPalCheck called, but PAL only exists in Alpha!\n");
338 return this->cpu
->simPalCheck(palFunc
, this->threadNumber
);
342 InOrderDynInst::syscall(int64_t callnum
)
344 cpu
->syscall(callnum
, this->threadNumber
);
349 InOrderDynInst::releaseReq(ResourceRequest
* req
)
351 std::list
<ResourceRequest
*>::iterator list_it
= reqList
.begin();
352 std::list
<ResourceRequest
*>::iterator list_end
= reqList
.end();
354 while(list_it
!= list_end
) {
355 if((*list_it
)->getResIdx() == req
->getResIdx() &&
356 (*list_it
)->getSlot() == req
->getSlot()) {
357 DPRINTF(InOrderDynInst
, "[tid:%u]: [sn:%i] Done with request "
358 "to %s.\n", threadNumber
, seqNum
, req
->res
->name());
359 reqList
.erase(list_it
);
365 panic("Releasing Res. Request That Isnt There!\n");
368 /** Records an integer source register being set to a value. */
370 InOrderDynInst::setIntSrc(int idx
, uint64_t val
)
372 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Source Value %i being set "
373 "to %#x.\n", threadNumber
, seqNum
, idx
, val
);
374 instSrc
[idx
].integer
= val
;
377 /** Records an fp register being set to a value. */
379 InOrderDynInst::setFloatSrc(int idx
, FloatReg val
)
381 instSrc
[idx
].dbl
= val
;
384 /** Records an fp register being set to an integer value. */
386 InOrderDynInst::setFloatRegBitsSrc(int idx
, uint64_t val
)
388 instSrc
[idx
].integer
= val
;
391 /** Reads a integer register. */
393 InOrderDynInst::readIntRegOperand(const StaticInst
*si
, int idx
, ThreadID tid
)
395 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Source Value %i read as %#x.\n",
396 threadNumber
, seqNum
, idx
, instSrc
[idx
].integer
);
397 return instSrc
[idx
].integer
;
400 /** Reads a FP register. */
402 InOrderDynInst::readFloatRegOperand(const StaticInst
*si
, int idx
)
404 return instSrc
[idx
].dbl
;
408 /** Reads a FP register as a integer. */
410 InOrderDynInst::readFloatRegOperandBits(const StaticInst
*si
, int idx
)
412 return instSrc
[idx
].integer
;
415 /** Reads a miscellaneous register. */
417 InOrderDynInst::readMiscReg(int misc_reg
)
419 return this->cpu
->readMiscReg(misc_reg
, threadNumber
);
423 /** Reads a misc. register, including any side-effects the read
424 * might have as defined by the architecture.
427 InOrderDynInst::readMiscRegOperand(const StaticInst
*si
, int idx
)
429 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Misc. Reg Source Value %i"
430 " read as %#x.\n", threadNumber
, seqNum
, idx
,
431 instSrc
[idx
].integer
);
432 return instSrc
[idx
].integer
;
436 /** Sets a misc. register, including any side-effects the write
437 * might have as defined by the architecture.
440 InOrderDynInst::setMiscRegOperand(const StaticInst
*si
, int idx
,
443 instResult
[idx
].type
= Integer
;
444 instResult
[idx
].val
.integer
= val
;
445 instResult
[idx
].tick
= curTick();
447 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting Misc Reg. Operand %i "
448 "being set to %#x.\n", threadNumber
, seqNum
, idx
, val
);
452 InOrderDynInst::readRegOtherThread(unsigned reg_idx
, ThreadID tid
)
455 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
458 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
459 return this->cpu
->readIntReg(reg_idx
, tid
);
460 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
461 reg_idx
-= FP_Base_DepTag
;
462 return this->cpu
->readFloatRegBits(reg_idx
, tid
);
464 reg_idx
-= Ctrl_Base_DepTag
;
465 return this->cpu
->readMiscReg(reg_idx
, tid
); // Misc. Register File
469 /** Sets a Integer register. */
471 InOrderDynInst::setIntRegOperand(const StaticInst
*si
, int idx
, IntReg val
)
473 instResult
[idx
].type
= Integer
;
474 instResult
[idx
].val
.integer
= val
;
475 instResult
[idx
].tick
= curTick();
477 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting Result Int Reg. %i "
478 "being set to %#x (result-tick:%i).\n",
479 threadNumber
, seqNum
, idx
, val
, instResult
[idx
].tick
);
482 /** Sets a FP register. */
484 InOrderDynInst::setFloatRegOperand(const StaticInst
*si
, int idx
, FloatReg val
)
486 instResult
[idx
].val
.dbl
= val
;
487 instResult
[idx
].type
= Float
;
488 instResult
[idx
].tick
= curTick();
490 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting Result Float Reg. %i "
491 "being set to %#x (result-tick:%i).\n",
492 threadNumber
, seqNum
, idx
, val
, instResult
[idx
].tick
);
495 /** Sets a FP register as a integer. */
497 InOrderDynInst::setFloatRegOperandBits(const StaticInst
*si
, int idx
,
500 instResult
[idx
].type
= Integer
;
501 instResult
[idx
].val
.integer
= val
;
502 instResult
[idx
].tick
= curTick();
504 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting Result Float Reg. %i "
505 "being set to %#x (result-tick:%i).\n",
506 threadNumber
, seqNum
, idx
, val
, instResult
[idx
].tick
);
509 /** Sets a misc. register, including any side-effects the write
510 * might have as defined by the architecture.
512 /* Alter this if/when wanting to *speculate* on Miscellaneous registers */
514 InOrderDynInst::setMiscReg(int misc_reg
, const MiscReg
&val
)
516 this->cpu
->setMiscReg(misc_reg
, val
, threadNumber
);
520 InOrderDynInst::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
,
523 if (tid
== InvalidThreadID
) {
524 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
527 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
528 this->cpu
->setIntReg(reg_idx
, val
, tid
);
529 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
530 reg_idx
-= FP_Base_DepTag
;
531 this->cpu
->setFloatRegBits(reg_idx
, val
, tid
);
533 reg_idx
-= Ctrl_Base_DepTag
;
534 this->cpu
->setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
539 InOrderDynInst::deallocateContext(int thread_num
)
541 this->cpu
->deallocateContext(thread_num
);
545 InOrderDynInst::readBytes(Addr addr
, uint8_t *data
,
546 unsigned size
, unsigned flags
)
548 return cpu
->read(this, addr
, data
, size
, flags
);
553 InOrderDynInst::read(Addr addr
, T
&data
, unsigned flags
)
556 traceData
->setAddr(addr
);
557 traceData
->setData(data
);
559 Fault fault
= readBytes(addr
, (uint8_t *)&data
, sizeof(T
), flags
);
560 data
= TheISA::gtoh(data
);
562 traceData
->setData(data
);
566 #ifndef DOXYGEN_SHOULD_SKIP_THIS
570 InOrderDynInst::read(Addr addr
, uint64_t &data
, unsigned flags
);
574 InOrderDynInst::read(Addr addr
, uint32_t &data
, unsigned flags
);
578 InOrderDynInst::read(Addr addr
, uint16_t &data
, unsigned flags
);
582 InOrderDynInst::read(Addr addr
, uint8_t &data
, unsigned flags
);
584 #endif //DOXYGEN_SHOULD_SKIP_THIS
588 InOrderDynInst::read(Addr addr
, double &data
, unsigned flags
)
590 return read(addr
, *(uint64_t*)&data
, flags
);
595 InOrderDynInst::read(Addr addr
, float &data
, unsigned flags
)
597 return read(addr
, *(uint32_t*)&data
, flags
);
602 InOrderDynInst::read(Addr addr
, int32_t &data
, unsigned flags
)
604 return read(addr
, (uint32_t&)data
, flags
);
608 InOrderDynInst::writeBytes(uint8_t *data
, unsigned size
,
609 Addr addr
, unsigned flags
, uint64_t *res
)
611 assert(sizeof(storeData
) >= size
);
612 memcpy(&storeData
, data
, size
);
613 return cpu
->write(this, (uint8_t *)&storeData
, size
, addr
, flags
, res
);
618 InOrderDynInst::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
622 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting store data to %#x.\n",
623 threadNumber
, seqNum
, storeData
);
625 traceData
->setAddr(addr
);
626 traceData
->setData(data
);
628 storeData
= TheISA::htog(data
);
629 return writeBytes((uint8_t*)&data
, sizeof(T
), addr
, flags
, res
);
632 #ifndef DOXYGEN_SHOULD_SKIP_THIS
635 InOrderDynInst::write(uint64_t data
, Addr addr
,
636 unsigned flags
, uint64_t *res
);
640 InOrderDynInst::write(uint32_t data
, Addr addr
,
641 unsigned flags
, uint64_t *res
);
645 InOrderDynInst::write(uint16_t data
, Addr addr
,
646 unsigned flags
, uint64_t *res
);
650 InOrderDynInst::write(uint8_t data
, Addr addr
,
651 unsigned flags
, uint64_t *res
);
653 #endif //DOXYGEN_SHOULD_SKIP_THIS
657 InOrderDynInst::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
659 return write(*(uint64_t*)&data
, addr
, flags
, res
);
664 InOrderDynInst::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
666 return write(*(uint32_t*)&data
, addr
, flags
, res
);
672 InOrderDynInst::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
674 return write((uint32_t)data
, addr
, flags
, res
);
679 InOrderDynInst::dump()
681 cprintf("T%d : %#08d `", threadNumber
, pc
.instAddr());
682 cout
<< staticInst
->disassemble(pc
.instAddr());
687 InOrderDynInst::dump(std::string
&outstring
)
689 std::ostringstream s
;
690 s
<< "T" << threadNumber
<< " : " << pc
<< " "
691 << staticInst
->disassemble(pc
.instAddr());
700 #include "base/hashmap.hh"
702 unsigned int MyHashFunc(const InOrderDynInst
*addr
)
704 unsigned a
= (unsigned)addr
;
705 unsigned hash
= (((a
>> 14) ^ ((a
>> 2) & 0xffff))) & 0x7FFFFFFF;
710 typedef m5::hash_map
<const InOrderDynInst
*, const InOrderDynInst
*,