9c03137215cfc967446546eb94d9afbf1b458baf
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
, Addr inst_PC
,
51 Addr pred_PC
, InstSeqNum seq_num
,
53 : staticInst(machInst
, inst_PC
), traceData(NULL
), cpu(cpu
)
58 nextPC
= PC
+ sizeof(MachInst
);
59 nextNPC
= nextPC
+ sizeof(MachInst
);
65 InOrderDynInst::InOrderDynInst(InOrderCPU
*cpu
,
66 InOrderThreadState
*state
,
70 : traceData(NULL
), cpu(cpu
)
79 InOrderDynInst::InOrderDynInst(StaticInstPtr
&_staticInst
)
80 : seqNum(0), staticInst(_staticInst
), traceData(NULL
)
85 InOrderDynInst::InOrderDynInst()
86 : seqNum(0), traceData(NULL
), cpu(cpu
)
91 int InOrderDynInst::instcount
= 0;
95 InOrderDynInst::setMachInst(ExtMachInst machInst
)
97 staticInst
= StaticInst::decode(machInst
, PC
);
99 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
100 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
103 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
104 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
105 this->_readySrcRegIdx
[i
] = 0;
110 InOrderDynInst::initVars()
115 split2ndAccess
= false;
125 nextInstStageNum
= 0;
127 for(int i
= 0; i
< MaxInstDestRegs
; i
++)
128 instResult
[i
].val
.integer
= 0;
132 memAddrReady
= false;
136 predictTaken
= false;
137 procDelaySlotOnMispred
= false;
142 // Also make this a parameter, or perhaps get it from xc or cpu.
147 // Initialize the fault to be NoFault.
150 // Make sure to have the renamed register entries set to the same
151 // as the normal register entries. It will allow the IQ to work
152 // without any modifications.
153 if (this->staticInst
) {
154 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
155 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
158 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
159 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
160 this->_readySrcRegIdx
[i
] = 0;
164 // Update Instruction Count for this instruction
166 if (instcount
> 500) {
167 fatal("Number of Active Instructions in CPU is too high. "
168 "(Not Dereferencing Ptrs. Correctly?)\n");
173 DPRINTF(InOrderDynInst
, "DynInst: [tid:%i] [sn:%lli] Instruction created. (active insts: %i)\n",
174 threadNumber
, seqNum
, instcount
);
178 InOrderDynInst::~InOrderDynInst()
180 if (fetchMemReq
!= 0x0) {
185 if (dataMemReq
!= 0x0) {
204 DPRINTF(InOrderDynInst
, "DynInst: [tid:%i] [sn:%lli] Instruction destroyed. (active insts: %i)\n",
205 threadNumber
, seqNum
, instcount
);
209 InOrderDynInst::setStaticInst(StaticInstPtr
&static_inst
)
211 this->staticInst
= static_inst
;
213 // Make sure to have the renamed register entries set to the same
214 // as the normal register entries. It will allow the IQ to work
215 // without any modifications.
216 if (this->staticInst
) {
217 for (int i
= 0; i
< this->staticInst
->numDestRegs(); i
++) {
218 _destRegIdx
[i
] = this->staticInst
->destRegIdx(i
);
221 for (int i
= 0; i
< this->staticInst
->numSrcRegs(); i
++) {
222 _srcRegIdx
[i
] = this->staticInst
->srcRegIdx(i
);
223 this->_readySrcRegIdx
[i
] = 0;
229 InOrderDynInst::execute()
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
->execute(this, this->traceData
);
240 this->thread
->inSyscall
= in_syscall
;
246 InOrderDynInst::calcEA()
248 this->fault
= this->staticInst
->eaComp(this, this->traceData
);
253 InOrderDynInst::initiateAcc()
255 // @todo: Pretty convoluted way to avoid squashing from happening
256 // when using the TC during an instruction's execution
257 // (specifically for instructions that have side-effects that use
258 // the TC). Fix this.
259 bool in_syscall
= this->thread
->inSyscall
;
260 this->thread
->inSyscall
= true;
262 this->fault
= this->staticInst
->initiateAcc(this, this->traceData
);
264 this->thread
->inSyscall
= in_syscall
;
271 InOrderDynInst::completeAcc(Packet
*pkt
)
273 this->fault
= this->staticInst
->completeAcc(pkt
, this, this->traceData
);
278 InstStage
*InOrderDynInst::addStage()
280 this->currentInstStage
= new InstStage(this, nextInstStageNum
++);
281 instStageList
.push_back( this->currentInstStage
);
282 return this->currentInstStage
;
285 InstStage
*InOrderDynInst::addStage(int stage_num
)
287 nextInstStageNum
= stage_num
;
288 return InOrderDynInst::addStage();
291 void InOrderDynInst::deleteStages() {
292 std::list
<InstStage
*>::iterator list_it
= instStageList
.begin();
293 std::list
<InstStage
*>::iterator list_end
= instStageList
.end();
295 while(list_it
!= list_end
) {
302 InOrderDynInst::memAccess()
304 return initiateAcc();
311 InOrderDynInst::hwrei()
313 panic("InOrderDynInst: hwrei: unimplemented\n");
319 InOrderDynInst::trap(Fault fault
)
321 this->cpu
->trap(fault
, this->threadNumber
);
326 InOrderDynInst::simPalCheck(int palFunc
)
328 #if THE_ISA != ALPHA_ISA
329 panic("simPalCheck called, but PAL only exists in Alpha!\n");
331 return this->cpu
->simPalCheck(palFunc
, this->threadNumber
);
335 InOrderDynInst::syscall(int64_t callnum
)
337 cpu
->syscall(callnum
, this->threadNumber
);
342 InOrderDynInst::prefetch(Addr addr
, unsigned flags
)
348 InOrderDynInst::writeHint(Addr addr
, int size
, unsigned flags
)
350 cpu
->writeHint(this);
354 * @todo Need to find a way to get the cache block size here.
357 InOrderDynInst::copySrcTranslate(Addr src
)
359 // Not currently supported.
364 * @todo Need to find a way to get the cache block size here.
367 InOrderDynInst::copy(Addr dest
)
369 // Not currently supported.
374 InOrderDynInst::releaseReq(ResourceRequest
* req
)
376 std::list
<ResourceRequest
*>::iterator list_it
= reqList
.begin();
377 std::list
<ResourceRequest
*>::iterator list_end
= reqList
.end();
379 while(list_it
!= list_end
) {
380 if((*list_it
)->getResIdx() == req
->getResIdx() &&
381 (*list_it
)->getSlot() == req
->getSlot()) {
382 DPRINTF(InOrderDynInst
, "[tid:%u]: [sn:%i] Done with request to %s.\n",
383 threadNumber
, seqNum
, req
->res
->name());
384 reqList
.erase(list_it
);
390 panic("Releasing Res. Request That Isnt There!\n");
393 /** Records an integer source register being set to a value. */
395 InOrderDynInst::setIntSrc(int idx
, uint64_t val
)
397 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Source Value %i being set to %#x.\n",
398 threadNumber
, seqNum
, idx
, val
);
399 instSrc
[idx
].integer
= val
;
402 /** Records an fp register being set to a value. */
404 InOrderDynInst::setFloatSrc(int idx
, FloatReg val
)
406 instSrc
[idx
].dbl
= val
;
409 /** Records an fp register being set to an integer value. */
411 InOrderDynInst::setFloatRegBitsSrc(int idx
, uint64_t val
)
413 instSrc
[idx
].integer
= val
;
416 /** Reads a integer register. */
418 InOrderDynInst::readIntRegOperand(const StaticInst
*si
, int idx
, ThreadID tid
)
420 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Source Value %i read as %#x.\n",
421 threadNumber
, seqNum
, idx
, instSrc
[idx
].integer
);
422 return instSrc
[idx
].integer
;
425 /** Reads a FP register. */
427 InOrderDynInst::readFloatRegOperand(const StaticInst
*si
, int idx
)
429 return instSrc
[idx
].dbl
;
433 /** Reads a FP register as a integer. */
435 InOrderDynInst::readFloatRegOperandBits(const StaticInst
*si
, int idx
)
437 return instSrc
[idx
].integer
;
440 /** Reads a miscellaneous register. */
442 InOrderDynInst::readMiscReg(int misc_reg
)
444 return this->cpu
->readMiscReg(misc_reg
, threadNumber
);
447 /** Reads a misc. register, including any side-effects the read
448 * might have as defined by the architecture.
451 InOrderDynInst::readMiscRegNoEffect(int misc_reg
)
453 return this->cpu
->readMiscRegNoEffect(misc_reg
, threadNumber
);
456 /** Reads a miscellaneous register. */
458 InOrderDynInst::readMiscRegOperandNoEffect(const StaticInst
*si
, int idx
)
460 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Misc. Reg Source Value %i"
461 " read as %#x.\n", threadNumber
, seqNum
, idx
,
462 instSrc
[idx
].integer
);
463 return instSrc
[idx
].integer
;
466 /** Reads a misc. register, including any side-effects the read
467 * might have as defined by the architecture.
470 InOrderDynInst::readMiscRegOperand(const StaticInst
*si
, int idx
)
472 // For In-Order, the side-effect of reading a register happens
473 // when explicitly executing a "ReadSrc" command. This simply returns
475 return readMiscRegOperandNoEffect(si
, idx
);
478 /** Sets a misc. register. */
480 InOrderDynInst::setMiscRegOperandNoEffect(const StaticInst
* si
, int idx
,
483 instResult
[idx
].type
= Integer
;
484 instResult
[idx
].val
.integer
= val
;
485 instResult
[idx
].tick
= curTick
;
487 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting Misc Reg. Operand %i "
488 "being set to %#x.\n", threadNumber
, seqNum
, idx
, val
);
491 /** Sets a misc. register, including any side-effects the write
492 * might have as defined by the architecture.
495 InOrderDynInst::setMiscRegOperand(const StaticInst
*si
, int idx
,
498 // For In-Order, the side-effect of setting a register happens
499 // when explicitly writing back the register value. This
500 // simply maintains the operand value.
501 setMiscRegOperandNoEffect(si
, idx
, val
);
505 InOrderDynInst::readRegOtherThread(unsigned reg_idx
, ThreadID tid
)
508 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
511 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
512 return this->cpu
->readIntReg(reg_idx
, tid
);
513 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
514 reg_idx
-= FP_Base_DepTag
;
515 return this->cpu
->readFloatRegBits(reg_idx
, tid
);
517 reg_idx
-= Ctrl_Base_DepTag
;
518 return this->cpu
->readMiscReg(reg_idx
, tid
); // Misc. Register File
522 /** Sets a Integer register. */
524 InOrderDynInst::setIntRegOperand(const StaticInst
*si
, int idx
, IntReg val
)
526 instResult
[idx
].type
= Integer
;
527 instResult
[idx
].val
.integer
= val
;
528 instResult
[idx
].tick
= curTick
;
531 /** Sets a FP register. */
533 InOrderDynInst::setFloatRegOperand(const StaticInst
*si
, int idx
, FloatReg val
)
535 instResult
[idx
].val
.dbl
= val
;
536 instResult
[idx
].type
= Float
;
538 instResult
[idx
].tick
= curTick
;
541 /** Sets a FP register as a integer. */
543 InOrderDynInst::setFloatRegOperandBits(const StaticInst
*si
, int idx
,
546 instResult
[idx
].type
= Integer
;
547 instResult
[idx
].val
.integer
= val
;
548 instResult
[idx
].tick
= curTick
;
551 /** Sets a misc. register. */
552 /* Alter this when wanting to *speculate* on Miscellaneous registers */
554 InOrderDynInst::setMiscRegNoEffect(int misc_reg
, const MiscReg
&val
)
556 this->cpu
->setMiscRegNoEffect(misc_reg
, val
, threadNumber
);
559 /** Sets a misc. register, including any side-effects the write
560 * might have as defined by the architecture.
562 /* Alter this if/when wanting to *speculate* on Miscellaneous registers */
564 InOrderDynInst::setMiscReg(int misc_reg
, const MiscReg
&val
)
566 this->cpu
->setMiscReg(misc_reg
, val
, threadNumber
);
570 InOrderDynInst::setRegOtherThread(unsigned reg_idx
, const MiscReg
&val
,
573 if (tid
== InvalidThreadID
) {
574 tid
= TheISA::getTargetThread(this->cpu
->tcBase(threadNumber
));
577 if (reg_idx
< FP_Base_DepTag
) { // Integer Register File
578 this->cpu
->setIntReg(reg_idx
, val
, tid
);
579 } else if (reg_idx
< Ctrl_Base_DepTag
) { // Float Register File
580 reg_idx
-= FP_Base_DepTag
;
581 this->cpu
->setFloatRegBits(reg_idx
, val
, tid
);
583 reg_idx
-= Ctrl_Base_DepTag
;
584 this->cpu
->setMiscReg(reg_idx
, val
, tid
); // Misc. Register File
589 InOrderDynInst::deallocateContext(int thread_num
)
591 this->cpu
->deallocateContext(thread_num
);
596 InOrderDynInst::read(Addr addr
, T
&data
, unsigned flags
)
598 return cpu
->read(this, addr
, data
, flags
);
601 #ifndef DOXYGEN_SHOULD_SKIP_THIS
605 InOrderDynInst::read(Addr addr
, uint64_t &data
, unsigned flags
);
609 InOrderDynInst::read(Addr addr
, uint32_t &data
, unsigned flags
);
613 InOrderDynInst::read(Addr addr
, uint16_t &data
, unsigned flags
);
617 InOrderDynInst::read(Addr addr
, uint8_t &data
, unsigned flags
);
619 #endif //DOXYGEN_SHOULD_SKIP_THIS
623 InOrderDynInst::read(Addr addr
, double &data
, unsigned flags
)
625 return read(addr
, *(uint64_t*)&data
, flags
);
630 InOrderDynInst::read(Addr addr
, float &data
, unsigned flags
)
632 return read(addr
, *(uint32_t*)&data
, flags
);
637 InOrderDynInst::read(Addr addr
, int32_t &data
, unsigned flags
)
639 return read(addr
, (uint32_t&)data
, flags
);
644 InOrderDynInst::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
646 //memcpy(memData, gtoh(data), sizeof(T));
649 DPRINTF(InOrderDynInst
, "[tid:%i]: [sn:%i] Setting store data to %#x.\n",
650 threadNumber
, seqNum
, memData
);
651 return cpu
->write(this, data
, addr
, flags
, res
);
654 #ifndef DOXYGEN_SHOULD_SKIP_THIS
657 InOrderDynInst::write(uint64_t data
, Addr addr
,
658 unsigned flags
, uint64_t *res
);
662 InOrderDynInst::write(uint32_t data
, Addr addr
,
663 unsigned flags
, uint64_t *res
);
667 InOrderDynInst::write(uint16_t data
, Addr addr
,
668 unsigned flags
, uint64_t *res
);
672 InOrderDynInst::write(uint8_t data
, Addr addr
,
673 unsigned flags
, uint64_t *res
);
675 #endif //DOXYGEN_SHOULD_SKIP_THIS
679 InOrderDynInst::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
681 return write(*(uint64_t*)&data
, addr
, flags
, res
);
686 InOrderDynInst::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
688 return write(*(uint32_t*)&data
, addr
, flags
, res
);
694 InOrderDynInst::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
696 return write((uint32_t)data
, addr
, flags
, res
);
701 InOrderDynInst::dump()
703 cprintf("T%d : %#08d `", threadNumber
, PC
);
704 cout
<< staticInst
->disassemble(PC
);
709 InOrderDynInst::dump(std::string
&outstring
)
711 std::ostringstream s
;
712 s
<< "T" << threadNumber
<< " : 0x" << PC
<< " "
713 << staticInst
->disassemble(PC
);
722 #include "base/hashmap.hh"
724 unsigned int MyHashFunc(const InOrderDynInst
*addr
)
726 unsigned a
= (unsigned)addr
;
727 unsigned hash
= (((a
>> 14) ^ ((a
>> 2) & 0xffff))) & 0x7FFFFFFF;
732 typedef m5::hash_map
<const InOrderDynInst
*, const InOrderDynInst
*, MyHashFunc
>