2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
29 #include "config/full_system.hh"
32 #include "sim/system.hh"
34 #include "sim/process.hh"
36 #include "sim/root.hh"
38 #include "cpu/cpu_exec_context.hh"
39 #include "cpu/exec_context.hh"
40 #include "cpu/o3/alpha_dyn_inst.hh"
41 #include "cpu/o3/alpha_impl.hh"
42 #include "cpu/o3/cpu.hh"
46 BaseFullCPU::BaseFullCPU(Params
¶ms
)
47 : BaseCPU(¶ms
), cpu_id(0)
52 FullO3CPU
<Impl
>::TickEvent::TickEvent(FullO3CPU
<Impl
> *c
)
53 : Event(&mainEventQueue
, CPU_Tick_Pri
), cpu(c
)
59 FullO3CPU
<Impl
>::TickEvent::process()
66 FullO3CPU
<Impl
>::TickEvent::description()
68 return "FullO3CPU tick event";
71 //Call constructor to all the pipeline stages here
73 FullO3CPU
<Impl
>::FullO3CPU(Params
¶ms
)
75 : BaseFullCPU(params
),
77 : BaseFullCPU(params
),
86 regFile(params
.numPhysIntRegs
, params
.numPhysFloatRegs
),
88 freeList(TheISA::NumIntRegs
, params
.numPhysIntRegs
,
89 TheISA::NumFloatRegs
, params
.numPhysFloatRegs
),
91 renameMap(TheISA::NumIntRegs
, params
.numPhysIntRegs
,
92 TheISA::NumFloatRegs
, params
.numPhysFloatRegs
,
95 TheISA::ZeroReg
+ TheISA::NumIntRegs
),
97 rob(params
.numROBEntries
, params
.squashWidth
),
99 // What to pass to these time buffers?
100 // For now just have these time buffers be pretty big.
112 system(params
.system
),
113 memCtrl(system
->memctrl
),
114 physmem(system
->physmem
),
119 // Hardcoded for a single thread!!
120 mem(params
.workload
[0]->getMemory()),
121 #endif // FULL_SYSTEM
123 icacheInterface(params
.icacheInterface
),
124 dcacheInterface(params
.dcacheInterface
),
125 deferRegistration(params
.defReg
),
132 thread
.resize(this->number_of_threads
);
135 for (int i
= 0; i
< this->number_of_threads
; ++i
) {
138 thread
[i
] = new CPUExecContext(this, 0, system
, itb
, dtb
, mem
);
139 system
->execContexts
[i
] = thread
[i
]->getProxy();
141 execContexts
.push_back(system
->execContexts
[i
]);
143 if (i
< params
.workload
.size()) {
144 DPRINTF(FullCPU
, "FullCPU: Workload[%i]'s starting PC is %#x, "
146 i
, params
.workload
[i
]->prog_entry
, thread
[i
]);
147 thread
[i
] = new CPUExecContext(this, i
, params
.workload
[i
], i
);
149 assert(params
.workload
[i
]->getMemory() != NULL
);
151 execContexts
.push_back(thread
[i
]->getProxy());
152 #endif // !FULL_SYSTEM
155 // Note that this is a hack so that my code which still uses xc-> will
156 // still work. I should remove this eventually
159 // The stages also need their CPU pointer setup. However this must be
160 // done at the upper level CPU because they have pointers to the upper
161 // level CPU, and not this FullO3CPU.
163 // Give each of the stages the time buffer they will use.
164 fetch
.setTimeBuffer(&timeBuffer
);
165 decode
.setTimeBuffer(&timeBuffer
);
166 rename
.setTimeBuffer(&timeBuffer
);
167 iew
.setTimeBuffer(&timeBuffer
);
168 commit
.setTimeBuffer(&timeBuffer
);
170 // Also setup each of the stages' queues.
171 fetch
.setFetchQueue(&fetchQueue
);
172 decode
.setFetchQueue(&fetchQueue
);
173 decode
.setDecodeQueue(&decodeQueue
);
174 rename
.setDecodeQueue(&decodeQueue
);
175 rename
.setRenameQueue(&renameQueue
);
176 iew
.setRenameQueue(&renameQueue
);
177 iew
.setIEWQueue(&iewQueue
);
178 commit
.setIEWQueue(&iewQueue
);
179 commit
.setRenameQueue(&renameQueue
);
181 // Setup the rename map for whichever stages need it.
182 rename
.setRenameMap(&renameMap
);
183 iew
.setRenameMap(&renameMap
);
185 // Setup the free list for whichever stages need it.
186 rename
.setFreeList(&freeList
);
187 renameMap
.setFreeList(&freeList
);
189 // Setup the ROB for whichever stages need it.
193 template <class Impl
>
194 FullO3CPU
<Impl
>::~FullO3CPU()
198 template <class Impl
>
200 FullO3CPU
<Impl
>::fullCPURegStats()
202 // Register any of the FullCPU's stats here.
205 template <class Impl
>
207 FullO3CPU
<Impl
>::tick()
209 DPRINTF(FullCPU
, "\n\nFullCPU: Ticking main, FullO3CPU.\n");
211 //Tick each of the stages if they're actually running.
212 //Will want to figure out a way to unschedule itself if they're all
213 //going to be idle for a long time.
224 // Now advance the time buffers, unless the stage is stalled.
225 timeBuffer
.advance();
227 fetchQueue
.advance();
228 decodeQueue
.advance();
229 renameQueue
.advance();
232 if (_status
== Running
&& !tickEvent
.scheduled())
233 tickEvent
.schedule(curTick
+ 1);
236 template <class Impl
>
238 FullO3CPU
<Impl
>::init()
240 if(!deferRegistration
)
242 this->registerExecContexts();
244 // Need to do a copy of the xc->regs into the CPU's regfile so
245 // that it can start properly.
247 ExecContext
*src_xc
= system
->execContexts
[0];
248 TheISA::initCPU(src_xc
, src_xc
->readCpuId());
250 ExecContext
*src_xc
= thread
[0]->getProxy();
252 // First loop through the integer registers.
253 for (int i
= 0; i
< TheISA::NumIntRegs
; ++i
)
255 regFile
.intRegFile
[i
] = src_xc
->readIntReg(i
);
258 // Then loop through the floating point registers.
259 for (int i
= 0; i
< TheISA::NumFloatRegs
; ++i
)
261 regFile
.floatRegFile
[i
].d
= src_xc
->readFloatRegDouble(i
);
262 regFile
.floatRegFile
[i
].q
= src_xc
->readFloatRegInt(i
);
265 // Then loop through the misc registers.
266 regFile.miscRegs.fpcr = src_xc->regs.miscRegs.fpcr;
267 regFile.miscRegs.uniq = src_xc->regs.miscRegs.uniq;
268 regFile.miscRegs.lock_flag = src_xc->regs.miscRegs.lock_flag;
269 regFile.miscRegs.lock_addr = src_xc->regs.miscRegs.lock_addr;
271 // Then finally set the PC and the next PC.
272 regFile
.pc
= src_xc
->readPC();
273 regFile
.npc
= src_xc
->readNextPC();
277 template <class Impl
>
279 FullO3CPU
<Impl
>::activateContext(int thread_num
, int delay
)
281 // Needs to set each stage to running as well.
283 scheduleTickEvent(delay
);
288 template <class Impl
>
290 FullO3CPU
<Impl
>::suspendContext(int thread_num
)
292 panic("suspendContext unimplemented!");
295 template <class Impl
>
297 FullO3CPU
<Impl
>::deallocateContext(int thread_num
)
299 panic("deallocateContext unimplemented!");
302 template <class Impl
>
304 FullO3CPU
<Impl
>::haltContext(int thread_num
)
306 panic("haltContext unimplemented!");
309 template <class Impl
>
311 FullO3CPU
<Impl
>::switchOut()
313 panic("FullO3CPU does not have a switch out function.\n");
316 template <class Impl
>
318 FullO3CPU
<Impl
>::takeOverFrom(BaseCPU
*oldCPU
)
320 BaseCPU::takeOverFrom(oldCPU
);
322 assert(!tickEvent
.scheduled());
324 // Set all status's to active, schedule the
326 for (int i
= 0; i
< execContexts
.size(); ++i
) {
327 ExecContext
*xc
= execContexts
[i
];
328 if (xc
->status() == ExecContext::Active
&& _status
!= Running
) {
330 tickEvent
.schedule(curTick
);
335 template <class Impl
>
337 FullO3CPU
<Impl
>::getAndIncrementInstSeq()
339 // Hopefully this works right.
340 return globalSeqNum
++;
343 template <class Impl
>
345 FullO3CPU
<Impl
>::readIntReg(int reg_idx
)
347 return regFile
.readIntReg(reg_idx
);
350 template <class Impl
>
352 FullO3CPU
<Impl
>::readFloatRegSingle(int reg_idx
)
354 return regFile
.readFloatRegSingle(reg_idx
);
357 template <class Impl
>
359 FullO3CPU
<Impl
>::readFloatRegDouble(int reg_idx
)
361 return regFile
.readFloatRegDouble(reg_idx
);
364 template <class Impl
>
366 FullO3CPU
<Impl
>::readFloatRegInt(int reg_idx
)
368 return regFile
.readFloatRegInt(reg_idx
);
371 template <class Impl
>
373 FullO3CPU
<Impl
>::setIntReg(int reg_idx
, uint64_t val
)
375 regFile
.setIntReg(reg_idx
, val
);
378 template <class Impl
>
380 FullO3CPU
<Impl
>::setFloatRegSingle(int reg_idx
, float val
)
382 regFile
.setFloatRegSingle(reg_idx
, val
);
385 template <class Impl
>
387 FullO3CPU
<Impl
>::setFloatRegDouble(int reg_idx
, double val
)
389 regFile
.setFloatRegDouble(reg_idx
, val
);
392 template <class Impl
>
394 FullO3CPU
<Impl
>::setFloatRegInt(int reg_idx
, uint64_t val
)
396 regFile
.setFloatRegInt(reg_idx
, val
);
399 template <class Impl
>
401 FullO3CPU
<Impl
>::readPC()
403 return regFile
.readPC();
406 template <class Impl
>
408 FullO3CPU
<Impl
>::setNextPC(uint64_t val
)
410 regFile
.setNextPC(val
);
413 template <class Impl
>
415 FullO3CPU
<Impl
>::setPC(Addr new_PC
)
417 regFile
.setPC(new_PC
);
420 template <class Impl
>
422 FullO3CPU
<Impl
>::addInst(DynInstPtr
&inst
)
424 instList
.push_back(inst
);
427 template <class Impl
>
429 FullO3CPU
<Impl
>::instDone()
431 // Keep an instruction count.
434 // Check for instruction-count-based events.
435 comInstEventQueue
[0]->serviceEvents(numInsts
);
438 template <class Impl
>
440 FullO3CPU
<Impl
>::removeBackInst(DynInstPtr
&inst
)
442 DynInstPtr inst_to_delete
;
444 // Walk through the instruction list, removing any instructions
445 // that were inserted after the given instruction, inst.
446 while (instList
.back() != inst
)
448 assert(!instList
.empty());
450 // Obtain the pointer to the instruction.
451 inst_to_delete
= instList
.back();
453 DPRINTF(FullCPU
, "FullCPU: Removing instruction %i, PC %#x\n",
454 inst_to_delete
->seqNum
, inst_to_delete
->readPC());
456 // Remove the instruction from the list.
459 // Mark it as squashed.
460 inst_to_delete
->setSquashed();
464 template <class Impl
>
466 FullO3CPU
<Impl
>::removeFrontInst(DynInstPtr
&inst
)
468 DynInstPtr inst_to_remove
;
470 // The front instruction should be the same one being asked to be removed.
471 assert(instList
.front() == inst
);
473 // Remove the front instruction.
474 inst_to_remove
= inst
;
475 instList
.pop_front();
477 DPRINTF(FullCPU
, "FullCPU: Removing committed instruction %#x, PC %#x\n",
478 inst_to_remove
, inst_to_remove
->readPC());
481 template <class Impl
>
483 FullO3CPU
<Impl
>::removeInstsNotInROB()
485 DPRINTF(FullCPU
, "FullCPU: Deleting instructions from instruction "
488 DynInstPtr rob_tail
= rob
.readTailInst();
490 removeBackInst(rob_tail
);
493 template <class Impl
>
495 FullO3CPU
<Impl
>::removeInstsUntil(const InstSeqNum
&seq_num
)
497 DPRINTF(FullCPU
, "FullCPU: Deleting instructions from instruction "
500 DynInstPtr inst_to_delete
;
502 while (instList
.back()->seqNum
> seq_num
) {
503 assert(!instList
.empty());
505 // Obtain the pointer to the instruction.
506 inst_to_delete
= instList
.back();
508 DPRINTF(FullCPU
, "FullCPU: Removing instruction %i, PC %#x\n",
509 inst_to_delete
->seqNum
, inst_to_delete
->readPC());
511 // Remove the instruction from the list.
512 instList
.back() = NULL
;
515 // Mark it as squashed.
516 inst_to_delete
->setSquashed();
521 template <class Impl
>
523 FullO3CPU
<Impl
>::removeAllInsts()
528 template <class Impl
>
530 FullO3CPU
<Impl
>::dumpInsts()
533 typename list
<DynInstPtr
>::iterator inst_list_it
= instList
.begin();
535 while (inst_list_it
!= instList
.end())
537 cprintf("Instruction:%i\nPC:%#x\nSN:%lli\nIssued:%i\nSquashed:%i\n\n",
538 num
, (*inst_list_it
)->readPC(), (*inst_list_it
)->seqNum
,
539 (*inst_list_it
)->isIssued(), (*inst_list_it
)->isSquashed());
545 template <class Impl
>
547 FullO3CPU
<Impl
>::wakeDependents(DynInstPtr
&inst
)
549 iew
.wakeDependents(inst
);
552 // Forward declaration of FullO3CPU.
553 template class FullO3CPU
<AlphaSimpleImpl
>;