CPU: Make physPort and getPhysPort available in SE mode.
[gem5.git] / src / cpu / inorder / inorder_dyn_inst.hh
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
3 * Copyright (c) 2004-2006 The Regents of The University of Michigan
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Kevin Lim
30 * Korey Sewell
31 */
32
33 #ifndef __CPU_INORDER_DYN_INST_HH__
34 #define __CPU_INORDER_DYN_INST_HH__
35
36 #include <bitset>
37 #include <list>
38 #include <string>
39
40 #include "arch/faults.hh"
41 #include "arch/isa_traits.hh"
42 #include "arch/mt.hh"
43 #include "arch/types.hh"
44 #include "arch/utility.hh"
45 #include "base/fast_alloc.hh"
46 #include "base/trace.hh"
47 #include "base/types.hh"
48 #include "config/full_system.hh"
49 #include "config/the_isa.hh"
50 #include "cpu/inorder/inorder_trace.hh"
51 #include "cpu/inorder/pipeline_traits.hh"
52 #include "cpu/inorder/resource.hh"
53 #include "cpu/inorder/resource_sked.hh"
54 #include "cpu/inorder/thread_state.hh"
55 #include "cpu/exetrace.hh"
56 #include "cpu/inst_seq.hh"
57 #include "cpu/op_class.hh"
58 #include "cpu/static_inst.hh"
59 #include "cpu/thread_context.hh"
60 #include "debug/InOrderDynInst.hh"
61 #include "mem/packet.hh"
62 #include "sim/system.hh"
63
64 #if THE_ISA == ALPHA_ISA
65 #include "arch/alpha/ev5.hh"
66 #endif
67
68 /**
69 * @file
70 * Defines a dynamic instruction context for a inorder CPU model.
71 */
72
73 // Forward declaration.
74 class ResourceRequest;
75 class Packet;
76
77 class InOrderDynInst : public FastAlloc, public RefCounted
78 {
79 public:
80 // Binary machine instruction type.
81 typedef TheISA::MachInst MachInst;
82 // Extended machine instruction type
83 typedef TheISA::ExtMachInst ExtMachInst;
84 // Logical register index type.
85 typedef TheISA::RegIndex RegIndex;
86 // Integer register type.
87 typedef TheISA::IntReg IntReg;
88 // Floating point register type.
89 typedef TheISA::FloatReg FloatReg;
90 // Floating point register type.
91 typedef TheISA::FloatRegBits FloatRegBits;
92 // Floating point register type.
93 typedef TheISA::MiscReg MiscReg;
94
95 typedef short int PhysRegIndex;
96
97 /** The refcounted DynInst pointer to be used. In most cases this is
98 * what should be used, and not DynInst*.
99 */
100 typedef RefCountingPtr<InOrderDynInst> DynInstPtr;
101
102 // The list of instructions iterator type.
103 typedef std::list<DynInstPtr>::iterator ListIt;
104
105 enum {
106 MaxInstSrcRegs = TheISA::MaxInstSrcRegs, /// Max source regs
107 MaxInstDestRegs = TheISA::MaxInstDestRegs, /// Max dest regs
108 };
109
110 public:
111 /** BaseDynInst constructor given a binary instruction.
112 * @param seq_num The sequence number of the instruction.
113 * @param cpu Pointer to the instruction's CPU.
114 * NOTE: Must set Binary Instrution through Member Function
115 */
116 InOrderDynInst(InOrderCPU *cpu, InOrderThreadState *state,
117 InstSeqNum seq_num, ThreadID tid, unsigned asid = 0);
118
119 /** InOrderDynInst destructor. */
120 ~InOrderDynInst();
121
122 public:
123 /** The sequence number of the instruction. */
124 InstSeqNum seqNum;
125
126 /** If this instruction is squashing, the number should we squash behind. */
127 InstSeqNum squashSeqNum;
128
129 enum Status {
130 RegDepMapEntry, /// Instruction is entered onto the RegDepMap
131 IqEntry, /// Instruction is in the IQ
132 RobEntry, /// Instruction is in the ROB
133 LsqEntry, /// Instruction is in the LSQ
134 Completed, /// Instruction has completed
135 ResultReady, /// Instruction has its result
136 CanIssue, /// Instruction can issue and execute
137 Issued, /// Instruction has issued
138 Executed, /// Instruction has executed
139 CanCommit, /// Instruction can commit
140 AtCommit, /// Instruction has reached commit
141 Committed, /// Instruction has committed
142 Squashed, /// Instruction is squashed
143 SquashedInIQ, /// Instruction is squashed in the IQ
144 SquashedInLSQ, /// Instruction is squashed in the LSQ
145 SquashedInROB, /// Instruction is squashed in the ROB
146 RecoverInst, /// Is a recover instruction
147 BlockingInst, /// Is a blocking instruction
148 ThreadsyncWait, /// Is a thread synchronization instruction
149 SerializeBefore, /// Needs to serialize on
150 /// instructions ahead of it
151 SerializeAfter, /// Needs to serialize instructions behind it
152 SerializeHandled, /// Serialization has been handled
153 RemoveList, /// Is Instruction on Remove List?
154 NumStatus
155 };
156
157 /** The status of this BaseDynInst. Several bits can be set. */
158 std::bitset<NumStatus> status;
159
160 /** The thread this instruction is from. */
161 short threadNumber;
162
163 /** data address space ID, for loads & stores. */
164 short asid;
165
166 /** The virtual processor number */
167 short virtProcNumber;
168
169 /** The StaticInst used by this BaseDynInst. */
170 StaticInstPtr staticInst;
171
172 /** InstRecord that tracks this instructions. */
173 Trace::InOrderTraceRecord *traceData;
174
175 /** Pointer to the Impl's CPU object. */
176 InOrderCPU *cpu;
177
178 /** Pointer to the thread state. */
179 InOrderThreadState *thread;
180
181 /** The kind of fault this instruction has generated. */
182 Fault fault;
183
184 /** The memory request. */
185 Request *req;
186
187 /** Pointer to the data for the memory access. */
188 uint8_t *memData;
189
190 /** Data used for a store for operation. */
191 uint64_t loadData;
192
193 /** Data used for a store for operation. */
194 uint64_t storeData;
195
196 /** List of active resource requests for this instruction */
197 std::list<ResourceRequest*> reqList;
198
199 /** The effective virtual address (lds & stores only). */
200 Addr effAddr;
201
202 /** The effective physical address. */
203 Addr physEffAddr;
204
205 /** The memory request flags (from translation). */
206 unsigned memReqFlags;
207
208 /** How many source registers are ready. */
209 unsigned readyRegs;
210
211 enum ResultType {
212 None,
213 Integer,
214 Float,
215 FloatBits,
216 Double
217 };
218
219 /** An instruction src/dest has to be one of these types */
220 struct InstValue {
221 IntReg intVal;
222 union {
223 FloatReg f;
224 FloatRegBits i;
225 } fpVal;
226
227 InstValue()
228 {
229 intVal = 0;
230 fpVal.i = 0;
231 }
232 };
233
234 /** Result of an instruction execution */
235 struct InstResult {
236 ResultType type;
237 InstValue res;
238 Tick tick;
239
240 InstResult()
241 : type(None), tick(0)
242 { }
243 };
244
245 /** The source of the instruction; assumes for now that there's only one
246 * destination register.
247 */
248 InstValue instSrc[MaxInstSrcRegs];
249
250 /** The result of the instruction; assumes for now that there's only one
251 * destination register.
252 */
253 InstResult instResult[MaxInstDestRegs];
254
255 /** PC of this instruction. */
256 TheISA::PCState pc;
257
258 /** Predicted next PC. */
259 TheISA::PCState predPC;
260
261 /** Address to get/write data from/to */
262 /* Fetching address when inst. starts, Data address for load/store after fetch*/
263 Addr memAddr;
264
265 /** Whether or not the source register is ready.
266 * @todo: Not sure this should be here vs the derived class.
267 */
268 bool _readySrcRegIdx[MaxInstSrcRegs];
269
270 /** Flattened register index of the destination registers of this
271 * instruction.
272 */
273 TheISA::RegIndex _flatDestRegIdx[TheISA::MaxInstDestRegs];
274
275 /** Flattened register index of the source registers of this
276 * instruction.
277 */
278 TheISA::RegIndex _flatSrcRegIdx[TheISA::MaxInstSrcRegs];
279
280 /** Physical register index of the destination registers of this
281 * instruction.
282 */
283 PhysRegIndex _destRegIdx[MaxInstDestRegs];
284
285 /** Physical register index of the source registers of this
286 * instruction.
287 */
288 PhysRegIndex _srcRegIdx[MaxInstSrcRegs];
289
290 /** Physical register index of the previous producers of the
291 * architected destinations.
292 */
293 PhysRegIndex _prevDestRegIdx[MaxInstDestRegs];
294
295 int nextStage;
296
297 private:
298 /** Function to initialize variables in the constructors. */
299 void initVars();
300
301 public:
302 Tick memTime;
303
304 PacketDataPtr splitMemData;
305 RequestPtr splitMemReq;
306 int totalSize;
307 int split2ndSize;
308 Addr split2ndAddr;
309 bool split2ndAccess;
310 uint8_t split2ndData;
311 PacketDataPtr split2ndDataPtr;
312 unsigned split2ndFlags;
313 bool splitInst;
314 int splitFinishCnt;
315 uint64_t *split2ndStoreDataPtr;
316 bool splitInstSked;
317
318 ////////////////////////////////////////////////////////////
319 //
320 // BASE INSTRUCTION INFORMATION.
321 //
322 ////////////////////////////////////////////////////////////
323 std::string instName()
324 { return (staticInst) ? staticInst->getName() : "undecoded-inst"; }
325
326 void setStaticInst(StaticInstPtr si);
327
328 ExtMachInst getMachInst() { return staticInst->machInst; }
329
330 /** Sets the StaticInst. */
331 void setStaticInst(StaticInstPtr &static_inst);
332
333 /** Sets the sequence number. */
334 void setSeqNum(InstSeqNum seq_num) { seqNum = seq_num; }
335
336 /** Sets the ASID. */
337 void setASID(short addr_space_id) { asid = addr_space_id; }
338
339 /** Reads the thread id. */
340 short readTid() { return threadNumber; }
341
342 /** Sets the thread id. */
343 void setTid(ThreadID tid) { threadNumber = tid; }
344
345 void setVpn(int id) { virtProcNumber = id; }
346
347 int readVpn() { return virtProcNumber; }
348
349 /** Sets the pointer to the thread state. */
350 void setThreadState(InOrderThreadState *state) { thread = state; }
351
352 /** Returns the thread context. */
353 ThreadContext *tcBase() { return thread->getTC(); }
354
355 /** Returns the fault type. */
356 Fault getFault() { return fault; }
357
358 /** Read this CPU's ID. */
359 int cpuId();
360
361 /** Read this context's system-wide ID **/
362 int contextId() { return thread->contextId(); }
363
364 ////////////////////////////////////////////////////////////
365 //
366 // INSTRUCTION TYPES - Forward checks to StaticInst object.
367 //
368 ////////////////////////////////////////////////////////////
369 bool isNop() const { return staticInst->isNop(); }
370 bool isMemRef() const { return staticInst->isMemRef(); }
371 bool isLoad() const { return staticInst->isLoad(); }
372 bool isStore() const { return staticInst->isStore(); }
373 bool isStoreConditional() const
374 { return staticInst->isStoreConditional(); }
375 bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
376 bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
377 bool isInteger() const { return staticInst->isInteger(); }
378 bool isFloating() const { return staticInst->isFloating(); }
379 bool isControl() const { return staticInst->isControl(); }
380 bool isCall() const { return staticInst->isCall(); }
381 bool isReturn() const { return staticInst->isReturn(); }
382 bool isDirectCtrl() const { return staticInst->isDirectCtrl(); }
383 bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
384 bool isCondCtrl() const { return staticInst->isCondCtrl(); }
385 bool isUncondCtrl() const { return staticInst->isUncondCtrl(); }
386 bool isCondDelaySlot() const { return staticInst->isCondDelaySlot(); }
387
388 bool isThreadSync() const { return staticInst->isThreadSync(); }
389 bool isSerializing() const { return staticInst->isSerializing(); }
390 bool isSerializeBefore() const
391 { return staticInst->isSerializeBefore() || status[SerializeBefore]; }
392 bool isSerializeAfter() const
393 { return staticInst->isSerializeAfter() || status[SerializeAfter]; }
394 bool isMemBarrier() const { return staticInst->isMemBarrier(); }
395 bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
396 bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
397 bool isQuiesce() const { return staticInst->isQuiesce(); }
398 bool isIprAccess() const { return staticInst->isIprAccess(); }
399 bool isUnverifiable() const { return staticInst->isUnverifiable(); }
400 bool isSyscall() const
401 { return staticInst->isSyscall(); }
402
403
404 /////////////////////////////////////////////
405 //
406 // RESOURCE SCHEDULING
407 //
408 /////////////////////////////////////////////
409 typedef ThePipeline::RSkedPtr RSkedPtr;
410 bool inFrontEnd;
411
412 RSkedPtr frontSked;
413 RSkedIt frontSked_end;
414
415 RSkedPtr backSked;
416 RSkedIt backSked_end;
417
418 RSkedIt curSkedEntry;
419
420 void setFrontSked(RSkedPtr front_sked)
421 {
422 frontSked = front_sked;
423 frontSked_end.init(frontSked);
424 frontSked_end = frontSked->end();
425 //DPRINTF(InOrderDynInst, "Set FrontSked End to : %x \n" ,
426 // frontSked_end.getIt()/*, frontSked->end()*/);
427 //assert(frontSked_end == frontSked->end());
428
429 // This initializes instruction to be able
430 // to walk the resource schedule
431 curSkedEntry.init(frontSked);
432 curSkedEntry = frontSked->begin();
433 }
434
435 void setBackSked(RSkedPtr back_sked)
436 {
437 backSked = back_sked;
438 backSked_end.init(backSked);
439 backSked_end = backSked->end();
440 }
441
442 void setNextStage(int stage_num) { nextStage = stage_num; }
443 int getNextStage() { return nextStage; }
444
445 /** Print Resource Schedule */
446 void printSked()
447 {
448 if (frontSked != NULL) {
449 frontSked->print();
450 }
451
452 if (backSked != NULL) {
453 backSked->print();
454 }
455 }
456
457 /** Return Next Resource Stage To Be Used */
458 int nextResStage()
459 {
460 assert((inFrontEnd && curSkedEntry != frontSked_end) ||
461 (!inFrontEnd && curSkedEntry != backSked_end));
462
463 return curSkedEntry->stageNum;
464 }
465
466
467 /** Return Next Resource To Be Used */
468 int nextResource()
469 {
470 assert((inFrontEnd && curSkedEntry != frontSked_end) ||
471 (!inFrontEnd && curSkedEntry != backSked_end));
472
473 return curSkedEntry->resNum;
474 }
475
476 /** Finish using a schedule entry, increment to next entry */
477 bool finishSkedEntry()
478 {
479 curSkedEntry++;
480
481 if (inFrontEnd && curSkedEntry == frontSked_end) {
482 DPRINTF(InOrderDynInst, "[sn:%i] Switching to "
483 "back end schedule.\n", seqNum);
484 assert(backSked != NULL);
485 curSkedEntry.init(backSked);
486 curSkedEntry = backSked->begin();
487 inFrontEnd = false;
488 } else if (!inFrontEnd && curSkedEntry == backSked_end) {
489 return true;
490 }
491
492 DPRINTF(InOrderDynInst, "[sn:%i] Next Stage: %i "
493 "Next Resource: %i.\n", seqNum, curSkedEntry->stageNum,
494 curSkedEntry->resNum);
495
496 return false;
497 }
498
499 /** Release a Resource Request (Currently Unused) */
500 void releaseReq(ResourceRequest* req);
501
502 ////////////////////////////////////////////
503 //
504 // INSTRUCTION EXECUTION
505 //
506 ////////////////////////////////////////////
507 /** Returns the opclass of this instruction. */
508 OpClass opClass() const { return staticInst->opClass(); }
509
510 /** Executes the instruction.*/
511 Fault execute();
512
513 unsigned curResSlot;
514
515 unsigned getCurResSlot() { return curResSlot; }
516
517 void setCurResSlot(unsigned slot_num) { curResSlot = slot_num; }
518
519 /** Calls a syscall. */
520 #if FULL_SYSTEM
521 /** Calls hardware return from error interrupt. */
522 Fault hwrei();
523 /** Traps to handle specified fault. */
524 void trap(Fault fault);
525 bool simPalCheck(int palFunc);
526 #else
527 short syscallNum;
528 #endif
529
530 /** Emulates a syscall. */
531 void syscall(int64_t callnum);
532
533 ////////////////////////////////////////////////////////////
534 //
535 // MULTITHREADING INTERFACE TO CPU MODELS
536 //
537 ////////////////////////////////////////////////////////////
538 virtual void deallocateContext(int thread_num);
539
540 ////////////////////////////////////////////////////////////
541 //
542 // PROGRAM COUNTERS - PC/NPC/NPC
543 //
544 ////////////////////////////////////////////////////////////
545 /** Read the PC of this instruction. */
546 const TheISA::PCState &pcState() const { return pc; }
547
548 /** Sets the PC of this instruction. */
549 void pcState(const TheISA::PCState &_pc) { pc = _pc; }
550
551 const Addr instAddr() { return pc.instAddr(); }
552 const Addr nextInstAddr() { return pc.nextInstAddr(); }
553 const MicroPC microPC() { return pc.microPC(); }
554
555 ////////////////////////////////////////////////////////////
556 //
557 // BRANCH PREDICTION
558 //
559 ////////////////////////////////////////////////////////////
560 /** Set the predicted target of this current instruction. */
561 void setPredTarg(const TheISA::PCState &predictedPC)
562 { predPC = predictedPC; }
563
564 /** Returns the predicted target of the branch. */
565 TheISA::PCState readPredTarg() { return predPC; }
566
567 /** Returns the predicted PC immediately after the branch. */
568 Addr predInstAddr() { return predPC.instAddr(); }
569
570 /** Returns the predicted PC two instructions after the branch */
571 Addr predNextInstAddr() { return predPC.nextInstAddr(); }
572
573 /** Returns the predicted micro PC after the branch */
574 Addr readPredMicroPC() { return predPC.microPC(); }
575
576 /** Returns whether the instruction was predicted taken or not. */
577 bool predTaken() { return predictTaken; }
578
579 /** Returns whether the instruction mispredicted. */
580 bool
581 mispredicted()
582 {
583 TheISA::PCState nextPC = pc;
584 TheISA::advancePC(nextPC, staticInst);
585 return !(nextPC == predPC);
586 }
587
588 /** Returns the branch target address. */
589 TheISA::PCState branchTarget() const
590 { return staticInst->branchTarget(pc); }
591
592 /** Checks whether or not this instruction has had its branch target
593 * calculated yet. For now it is not utilized and is hacked to be
594 * always false.
595 * @todo: Actually use this instruction.
596 */
597 bool doneTargCalc() { return false; }
598
599 void setBranchPred(bool prediction) { predictTaken = prediction; }
600
601 int squashingStage;
602
603 bool predictTaken;
604
605 bool procDelaySlotOnMispred;
606
607 void setSquashInfo(unsigned stage_num);
608
609 ////////////////////////////////////////////
610 //
611 // MEMORY ACCESS
612 //
613 ////////////////////////////////////////////
614
615 Fault readMem(Addr addr, uint8_t *data, unsigned size, unsigned flags);
616
617 Fault writeMem(uint8_t *data, unsigned size,
618 Addr addr, unsigned flags, uint64_t *res);
619
620 /** Initiates a memory access - Calculate Eff. Addr & Initiate Memory
621 * Access Only valid for memory operations.
622 */
623 Fault initiateAcc();
624
625 /** Completes a memory access - Only valid for memory operations. */
626 Fault completeAcc(Packet *pkt);
627
628 /** Calculates Eff. Addr. part of a memory instruction. */
629 Fault calcEA();
630
631 /** Read Effective Address from instruction & do memory access */
632 Fault memAccess();
633
634 RequestPtr fetchMemReq;
635 RequestPtr dataMemReq;
636
637 bool memAddrReady;
638
639 bool validMemAddr()
640 { return memAddrReady; }
641
642 void setMemAddr(Addr addr)
643 { memAddr = addr; memAddrReady = true;}
644
645 void unsetMemAddr()
646 { memAddrReady = false;}
647
648 Addr getMemAddr()
649 { return memAddr; }
650
651 /** Sets the effective address. */
652 void setEA(Addr &ea) { instEffAddr = ea; eaCalcDone = true; }
653
654 /** Returns the effective address. */
655 const Addr &getEA() const { return instEffAddr; }
656
657 /** Returns whether or not the eff. addr. calculation has been completed.*/
658 bool doneEACalc() { return eaCalcDone; }
659
660 /** Returns whether or not the eff. addr. source registers are ready.
661 * Assume that src registers 1..n-1 are the ones that the
662 * EA calc depends on. (i.e. src reg 0 is the source of the data to be
663 * stored)
664 */
665 bool eaSrcsReady()
666 {
667 for (int i = 1; i < numSrcRegs(); ++i) {
668 if (!_readySrcRegIdx[i])
669 return false;
670 }
671
672 return true;
673 }
674
675 //////////////////////////////////////////////////
676 //
677 // SOURCE-DESTINATION REGISTER INDEXING
678 //
679 //////////////////////////////////////////////////
680 /** Returns the number of source registers. */
681 int8_t numSrcRegs() const { return staticInst->numSrcRegs(); }
682
683 /** Returns the number of destination registers. */
684 int8_t numDestRegs() const { return staticInst->numDestRegs(); }
685
686 // the following are used to track physical register usage
687 // for machines with separate int & FP reg files
688 int8_t numFPDestRegs() const { return staticInst->numFPDestRegs(); }
689 int8_t numIntDestRegs() const { return staticInst->numIntDestRegs(); }
690
691 /** Returns the logical register index of the i'th destination register. */
692 RegIndex destRegIdx(int i) const { return staticInst->destRegIdx(i); }
693
694 /** Returns the logical register index of the i'th source register. */
695 RegIndex srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
696
697 //////////////////////////////////////////////////
698 //
699 // RENAME/PHYSICAL REGISTER FILE SUPPORT
700 //
701 //////////////////////////////////////////////////
702 /** Returns the physical register index of the i'th destination
703 * register.
704 */
705 PhysRegIndex renamedDestRegIdx(int idx) const
706 {
707 return _destRegIdx[idx];
708 }
709
710 /** Returns the physical register index of the i'th source register. */
711 PhysRegIndex renamedSrcRegIdx(int idx) const
712 {
713 return _srcRegIdx[idx];
714 }
715
716 /** Flattens a source architectural register index into a logical index.
717 */
718 void flattenSrcReg(int idx, TheISA::RegIndex flattened_src)
719 {
720 _flatSrcRegIdx[idx] = flattened_src;
721 }
722
723 /** Flattens a destination architectural register index into a logical
724 * index.
725 */
726 void flattenDestReg(int idx, TheISA::RegIndex flattened_dest)
727 {
728 _flatDestRegIdx[idx] = flattened_dest;
729 }
730
731 /** Returns the flattened register index of the i'th destination
732 * register.
733 */
734 TheISA::RegIndex flattenedDestRegIdx(int idx) const
735 {
736 return _flatDestRegIdx[idx];
737 }
738
739 /** Returns the flattened register index of the i'th source register */
740 TheISA::RegIndex flattenedSrcRegIdx(int idx) const
741 {
742 return _flatSrcRegIdx[idx];
743 }
744
745 /** Returns the physical register index of the previous physical register
746 * that remapped to the same logical register index.
747 */
748 PhysRegIndex prevDestRegIdx(int idx) const
749 {
750 return _prevDestRegIdx[idx];
751 }
752
753 /** Returns if a source register is ready. */
754 bool isReadySrcRegIdx(int idx) const
755 {
756 return this->_readySrcRegIdx[idx];
757 }
758
759 /** Records that one of the source registers is ready. */
760 void markSrcRegReady()
761 {
762 if (++readyRegs == numSrcRegs()) {
763 status.set(CanIssue);
764 }
765 }
766
767 /** Marks a specific register as ready. */
768 void markSrcRegReady(RegIndex src_idx)
769 {
770 _readySrcRegIdx[src_idx] = true;
771
772 markSrcRegReady();
773 }
774
775 /** Renames a destination register to a physical register. Also records
776 * the previous physical register that the logical register mapped to.
777 */
778 void renameDestReg(int idx,
779 PhysRegIndex renamed_dest,
780 PhysRegIndex previous_rename)
781 {
782 _destRegIdx[idx] = renamed_dest;
783 _prevDestRegIdx[idx] = previous_rename;
784 }
785
786 /** Renames a source logical register to the physical register which
787 * has/will produce that logical register's result.
788 * @todo: add in whether or not the source register is ready.
789 */
790 void renameSrcReg(int idx, PhysRegIndex renamed_src)
791 {
792 _srcRegIdx[idx] = renamed_src;
793 }
794
795
796 PhysRegIndex readDestRegIdx(int idx)
797 {
798 return _destRegIdx[idx];
799 }
800
801 void setDestRegIdx(int idx, PhysRegIndex dest_idx)
802 {
803 _destRegIdx[idx] = dest_idx;
804 }
805
806 int getDestIdxNum(PhysRegIndex dest_idx)
807 {
808 for (int i=0; i < staticInst->numDestRegs(); i++) {
809 if (_flatDestRegIdx[i] == dest_idx)
810 return i;
811 }
812
813 return -1;
814 }
815
816 PhysRegIndex readSrcRegIdx(int idx)
817 {
818 return _srcRegIdx[idx];
819 }
820
821 void setSrcRegIdx(int idx, PhysRegIndex src_idx)
822 {
823 _srcRegIdx[idx] = src_idx;
824 }
825
826 int getSrcIdxNum(PhysRegIndex src_idx)
827 {
828 for (int i=0; i < staticInst->numSrcRegs(); i++) {
829 if (_srcRegIdx[i] == src_idx)
830 return i;
831 }
832
833 return -1;
834 }
835
836 ////////////////////////////////////////////////////
837 //
838 // SOURCE-DESTINATION REGISTER VALUES
839 //
840 ////////////////////////////////////////////////////
841
842 /** Functions that sets an integer or floating point
843 * source register to a value. */
844 void setIntSrc(int idx, uint64_t val);
845 void setFloatSrc(int idx, FloatReg val);
846 void setFloatRegBitsSrc(int idx, TheISA::FloatRegBits val);
847
848 TheISA::IntReg* getIntSrcPtr(int idx) { return &instSrc[idx].intVal; }
849 uint64_t readIntSrc(int idx) { return instSrc[idx].intVal; }
850
851 /** These Instructions read a integer/float/misc. source register
852 * value in the instruction. The instruction's execute function will
853 * call these and it is the interface that is used by the ISA descr.
854 * language (which is why the name isnt readIntSrc(...)) Note: That
855 * the source reg. value is set using the setSrcReg() function.
856 */
857 IntReg readIntRegOperand(const StaticInst *si, int idx, ThreadID tid = 0);
858 FloatReg readFloatRegOperand(const StaticInst *si, int idx);
859 TheISA::FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx);
860 MiscReg readMiscReg(int misc_reg);
861 MiscReg readMiscRegNoEffect(int misc_reg);
862 MiscReg readMiscRegOperand(const StaticInst *si, int idx);
863 MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx);
864
865 /** Returns the result value instruction. */
866 ResultType resultType(int idx)
867 {
868 return instResult[idx].type;
869 }
870
871 IntReg readIntResult(int idx)
872 {
873 return instResult[idx].res.intVal;
874 }
875
876 FloatReg readFloatResult(int idx)
877 {
878 return instResult[idx].res.fpVal.f;
879 }
880
881 FloatRegBits readFloatBitsResult(int idx)
882 {
883 return instResult[idx].res.fpVal.i;
884 }
885
886 Tick readResultTime(int idx) { return instResult[idx].tick; }
887
888 IntReg* getIntResultPtr(int idx) { return &instResult[idx].res.intVal; }
889
890 /** This is the interface that an instruction will use to write
891 * it's destination register.
892 */
893 void setIntRegOperand(const StaticInst *si, int idx, IntReg val);
894 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val);
895 void setFloatRegOperandBits(const StaticInst *si, int idx,
896 TheISA::FloatRegBits val);
897 void setMiscReg(int misc_reg, const MiscReg &val);
898 void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
899 void setMiscRegOperand(const StaticInst *si, int idx, const MiscReg &val);
900 void setMiscRegOperandNoEffect(const StaticInst *si, int idx,
901 const MiscReg &val);
902
903 virtual uint64_t readRegOtherThread(unsigned idx,
904 ThreadID tid = InvalidThreadID);
905 virtual void setRegOtherThread(unsigned idx, const uint64_t &val,
906 ThreadID tid = InvalidThreadID);
907
908 /** Returns the number of consecutive store conditional failures. */
909 unsigned readStCondFailures()
910 { return thread->storeCondFailures; }
911
912 /** Sets the number of consecutive store conditional failures. */
913 void setStCondFailures(unsigned sc_failures)
914 { thread->storeCondFailures = sc_failures; }
915
916 //////////////////////////////////////////////////////////////
917 //
918 // INSTRUCTION STATUS FLAGS (READ/SET)
919 //
920 //////////////////////////////////////////////////////////////
921 /** Sets this instruction as entered on the CPU Reg Dep Map */
922 void setRegDepEntry() { status.set(RegDepMapEntry); }
923
924 /** Unsets this instruction as entered on the CPU Reg Dep Map */
925 void clearRegDepEntry() { status.reset(RegDepMapEntry); }
926
927 /** Returns whether or not the entry is on the CPU Reg Dep Map */
928 bool isRegDepEntry() const { return status[RegDepMapEntry]; }
929
930 /** Sets this instruction as entered on the CPU Reg Dep Map */
931 void setRemoveList() { status.set(RemoveList); }
932
933 /** Returns whether or not the entry is on the CPU Reg Dep Map */
934 bool isRemoveList() const { return status[RemoveList]; }
935
936 /** Sets this instruction as completed. */
937 void setCompleted() { status.set(Completed); }
938
939 /** Returns whether or not this instruction is completed. */
940 bool isCompleted() const { return status[Completed]; }
941
942 /** Marks the result as ready. */
943 void setResultReady() { status.set(ResultReady); }
944
945 /** Returns whether or not the result is ready. */
946 bool isResultReady() const { return status[ResultReady]; }
947
948 /** Sets this instruction as ready to issue. */
949 void setCanIssue() { status.set(CanIssue); }
950
951 /** Returns whether or not this instruction is ready to issue. */
952 bool readyToIssue() const { return status[CanIssue]; }
953
954 /** Sets this instruction as issued from the IQ. */
955 void setIssued() { status.set(Issued); }
956
957 /** Returns whether or not this instruction has issued. */
958 bool isIssued() const { return status[Issued]; }
959
960 /** Sets this instruction as executed. */
961 void setExecuted() { status.set(Executed); }
962
963 /** Returns whether or not this instruction has executed. */
964 bool isExecuted() const { return status[Executed]; }
965
966 /** Sets this instruction as ready to commit. */
967 void setCanCommit() { status.set(CanCommit); }
968
969 /** Clears this instruction as being ready to commit. */
970 void clearCanCommit() { status.reset(CanCommit); }
971
972 /** Returns whether or not this instruction is ready to commit. */
973 bool readyToCommit() const { return status[CanCommit]; }
974
975 void setAtCommit() { status.set(AtCommit); }
976
977 bool isAtCommit() { return status[AtCommit]; }
978
979 /** Sets this instruction as committed. */
980 void setCommitted() { status.set(Committed); }
981
982 /** Returns whether or not this instruction is committed. */
983 bool isCommitted() const { return status[Committed]; }
984
985 /** Sets this instruction as squashed. */
986 void setSquashed() { status.set(Squashed); }
987
988 /** Returns whether or not this instruction is squashed. */
989 bool isSquashed() const { return status[Squashed]; }
990
991 /** Temporarily sets this instruction as a serialize before instruction. */
992 void setSerializeBefore() { status.set(SerializeBefore); }
993
994 /** Clears the serializeBefore part of this instruction. */
995 void clearSerializeBefore() { status.reset(SerializeBefore); }
996
997 /** Checks if this serializeBefore is only temporarily set. */
998 bool isTempSerializeBefore() { return status[SerializeBefore]; }
999
1000 /** Temporarily sets this instruction as a serialize after instruction. */
1001 void setSerializeAfter() { status.set(SerializeAfter); }
1002
1003 /** Clears the serializeAfter part of this instruction.*/
1004 void clearSerializeAfter() { status.reset(SerializeAfter); }
1005
1006 /** Checks if this serializeAfter is only temporarily set. */
1007 bool isTempSerializeAfter() { return status[SerializeAfter]; }
1008
1009 /** Sets the serialization part of this instruction as handled. */
1010 void setSerializeHandled() { status.set(SerializeHandled); }
1011
1012 /** Checks if the serialization part of this instruction has been
1013 * handled. This does not apply to the temporary serializing
1014 * state; it only applies to this instruction's own permanent
1015 * serializing state.
1016 */
1017 bool isSerializeHandled() { return status[SerializeHandled]; }
1018
1019 private:
1020 /** Instruction effective address.
1021 * @todo: Consider if this is necessary or not.
1022 */
1023 Addr instEffAddr;
1024
1025 /** Whether or not the effective address calculation is completed.
1026 * @todo: Consider if this is necessary or not.
1027 */
1028 bool eaCalcDone;
1029
1030 public:
1031 /** Load queue index. */
1032 int16_t lqIdx;
1033
1034 /** Store queue index. */
1035 int16_t sqIdx;
1036
1037 /** Iterator pointing to this BaseDynInst in the list of all insts. */
1038 ListIt instListIt;
1039
1040 bool onInstList;
1041
1042 /** Returns iterator to this instruction in the list of all insts. */
1043 ListIt getInstListIt() { return instListIt; }
1044
1045 /** Sets iterator for this instruction in the list of all insts. */
1046 void setInstListIt(ListIt _instListIt) { onInstList = true; instListIt = _instListIt; }
1047
1048 /** Count of total number of dynamic instructions. */
1049 static int instcount;
1050
1051 void resetInstCount();
1052
1053 /** Dumps out contents of this BaseDynInst. */
1054 void dump();
1055
1056 /** Dumps out contents of this BaseDynInst into given string. */
1057 void dump(std::string &outstring);
1058
1059 //inline int curCount() { return curCount(); }
1060 };
1061
1062
1063 #endif // __CPU_BASE_DYN_INST_HH__