2 * Copyright (c) 2006 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.
31 #include "sim/faults.hh"
32 #include "arch/types.hh"
33 #include "config/the_isa.hh"
34 #include "cpu/ozone/inorder_back_end.hh"
35 #include "cpu/ozone/thread_state.hh"
38 InorderBackEnd<Impl>::InorderBackEnd(Params *params)
39 : squashPending(false),
42 faultFromFetch(NoFault),
43 interruptBlocked(false),
44 cacheCompletionEvent(this),
45 dcacheInterface(params->dcacheInterface),
46 width(params->backEndWidth),
47 latency(params->backEndLatency),
48 squashLatency(params->backEndSquashLatency),
49 numInstsToWB(0, latency + 1)
51 instsAdded = numInstsToWB.getWire(latency);
52 instsToExecute = numInstsToWB.getWire(0);
55 memReq->data = new uint8_t[64];
61 InorderBackEnd<Impl>::name() const
63 return cpu->name() + ".inorderbackend";
68 InorderBackEnd<Impl>::setXC(ExecContext *xc_ptr)
76 InorderBackEnd<Impl>::setThreadState(OzoneThreadState<Impl> *thread_ptr)
79 thread->setFuncExeInst(0);
85 InorderBackEnd<Impl>::checkInterrupts()
87 //Check if there are any outstanding interrupts
88 //Handle the interrupts
93 if (thread->readMiscRegNoEffect(IPR_ASTRR))
94 panic("asynchronous traps not implemented\n");
96 if (thread->readMiscRegNoEffect(IPR_SIRR)) {
97 for (int i = INTLEVEL_SOFTWARE_MIN;
98 i < INTLEVEL_SOFTWARE_MAX; i++) {
99 if (thread->readMiscRegNoEffect(IPR_SIRR) & (ULL(1) << i)) {
100 // See table 4-19 of the 21164 hardware reference
101 ipl = (i - INTLEVEL_SOFTWARE_MIN) + 1;
102 summary |= (ULL(1) << i);
107 uint64_t interrupts = cpu->intr_status();
110 for (int i = INTLEVEL_EXTERNAL_MIN;
111 i < INTLEVEL_EXTERNAL_MAX; i++) {
112 if (interrupts & (ULL(1) << i)) {
113 // See table 4-19 of the 21164 hardware reference
115 summary |= (ULL(1) << i);
120 if (ipl && ipl > thread->readMiscRegNoEffect(IPR_IPLR)) {
121 thread->inSyscall = true;
123 thread->setMiscRegNoEffect(IPR_ISR, summary);
124 thread->setMiscRegNoEffect(IPR_INTID, ipl);
125 Fault(new InterruptFault)->invoke(xc);
126 DPRINTF(Flow, "Interrupt! IPLR=%d ipl=%d summary=%x\n",
127 thread->readMiscRegNoEffect(IPR_IPLR), ipl, summary);
129 // May need to go 1 inst prior
130 squashPending = true;
132 thread->inSyscall = false;
134 setSquashInfoFromXC();
139 template <class Impl>
141 InorderBackEnd<Impl>::tick()
143 // Squash due to an external source
144 // Not sure if this or an interrupt has higher priority
146 squash(squashSeqNum, squashNextPC);
150 // if (interrupt) then set thread PC, stall front end, record that
151 // I'm waiting for it to drain. (for now just squash)
153 if (interruptBlocked || cpu->checkInterrupts(tc)) {
155 interruptBlocked = true;
157 } else if (robEmpty() && (PC & 0x3)) {
158 // Will need to let the front end continue a bit until
159 // we're out of pal mode. Hopefully we never get into an
161 interruptBlocked = false;
163 interruptBlocked = false;
170 if (status != DcacheMissLoadStall &&
171 status != DcacheMissStoreStall) {
172 for (int i = 0; i < width && (*instsAdded) < width; ++i) {
173 DynInstPtr inst = frontEnd->getInst();
178 instList.push_back(inst);
184 if (faultFromFetch && robEmpty() && frontEnd->isEmpty()) {
195 template <class Impl>
197 InorderBackEnd<Impl>::executeInsts()
199 bool completed_last_inst = true;
200 int insts_to_execute = *instsToExecute;
203 while (insts_to_execute > 0) {
204 assert(!instList.empty());
205 DynInstPtr inst = instList.front();
207 commitPC = inst->readPC();
209 thread->setPC(commitPC);
210 thread->setNextPC(inst->readNextPC());
217 assert(!thread->inSyscall && !thread->trapPending);
218 oldpc = thread->readPC();
219 cpu->system->pcEventQueue.service(
220 thread->getXCProxy());
222 } while (oldpc != thread->readPC());
224 DPRINTF(IBE, "PC skip function event, stopping commit\n");
225 completed_last_inst = false;
226 squashPending = true;
231 Fault inst_fault = NoFault;
233 if (status == DcacheMissComplete) {
234 DPRINTF(IBE, "Completing inst [sn:%lli]\n", inst->seqNum);
236 } else if (inst->isMemRef() && status != DcacheMissComplete &&
237 (!inst->isDataPrefetch() && !inst->isInstPrefetch())) {
238 DPRINTF(IBE, "Initiating mem op inst [sn:%lli] PC: %#x\n",
239 inst->seqNum, inst->readPC());
241 cacheCompletionEvent.inst = inst;
242 inst_fault = inst->initiateAcc();
243 if (inst_fault == NoFault &&
244 status != DcacheMissLoadStall &&
245 status != DcacheMissStoreStall) {
246 inst_fault = inst->completeAcc();
248 ++thread->funcExeInst;
250 DPRINTF(IBE, "Executing inst [sn:%lli] PC: %#x\n",
251 inst->seqNum, inst->readPC());
252 inst_fault = inst->execute();
253 ++thread->funcExeInst;
256 // Will need to be able to break this loop in case the load
257 // misses. Split access/complete ops would be useful here
258 // with writeback events.
259 if (status == DcacheMissLoadStall) {
260 *instsToExecute = insts_to_execute;
262 completed_last_inst = false;
264 } else if (status == DcacheMissStoreStall) {
265 // Figure out how to fix this hack. Probably have DcacheMissLoad
266 // vs DcacheMissStore.
267 *instsToExecute = insts_to_execute;
268 completed_last_inst = false;
270 instList.pop_front();
272 if (inst->traceData) {
273 inst->traceData->finalize();
277 // Don't really need to stop for a store stall as long as
278 // the memory system is able to handle store forwarding
279 // and such. Breaking out might help avoid the cache
280 // interface becoming blocked.
285 inst->setResultReady();
286 inst->setCanCommit();
288 instList.pop_front();
293 if (inst->traceData) {
294 inst->traceData->finalize();
295 inst->traceData = NULL;
298 if (inst_fault != NoFault) {
300 DPRINTF(IBE, "Inst [sn:%lli] PC %#x has a fault\n",
301 inst->seqNum, inst->readPC());
303 assert(!thread->inSyscall);
305 thread->inSyscall = true;
307 // Hack for now; DTB will sometimes need the machine instruction
308 // for when faults happen. So we will set it here, prior to the
309 // DTB possibly needing it for this translation.
311 static_cast<TheISA::MachInst>(inst->staticInst->machInst));
313 // Consider holding onto the trap and waiting until the trap event
314 // happens for this to be executed.
315 inst_fault->invoke(xc);
317 // Exit state update mode to avoid accidental updating.
318 thread->inSyscall = false;
320 squashPending = true;
322 // Generate trap squash event.
323 // generateTrapEvent(tid);
324 completed_last_inst = false;
326 #else // !FULL_SYSTEM
327 panic("fault (%d) detected @ PC %08p", inst_fault,
329 #endif // FULL_SYSTEM
332 for (int i = 0; i < inst->numDestRegs(); ++i) {
333 renameTable[inst->destRegIdx(i)] = inst;
334 thread->renameTable[inst->destRegIdx(i)] = inst;
338 inst->clearDependents();
340 comm->access(0)->doneSeqNum = inst->seqNum;
342 if (inst->mispredicted()) {
343 squash(inst->seqNum, inst->readNextPC());
345 thread->setNextPC(inst->readNextPC());
348 } else if (squashPending) {
349 // Something external happened that caused the CPU to squash.
350 // Break out of commit and handle the squash next cycle.
353 // If it didn't mispredict, then it executed fine. Send back its
354 // registers and BP info? What about insts that may still have
355 // latency, like loads? Probably can send back the information after
358 // keep an instruction count
363 frontEnd->addFreeRegs(freed_regs);
365 assert(insts_to_execute >= 0);
367 // Should only advance this if I have executed all instructions.
368 if (insts_to_execute == 0) {
369 numInstsToWB.advance();
372 // Should I set the PC to the next PC here? What do I set next PC to?
373 if (completed_last_inst) {
374 thread->setPC(thread->readNextPC());
375 thread->setNextPC(thread->readPC() + sizeof(MachInst));
379 setSquashInfoFromXC();
383 template <class Impl>
385 InorderBackEnd<Impl>::handleFault()
387 DPRINTF(Commit, "Handling fault from fetch\n");
389 assert(!thread->inSyscall);
391 thread->inSyscall = true;
393 // Consider holding onto the trap and waiting until the trap event
394 // happens for this to be executed.
395 faultFromFetch->invoke(xc);
397 // Exit state update mode to avoid accidental updating.
398 thread->inSyscall = false;
400 squashPending = true;
402 setSquashInfoFromXC();
405 template <class Impl>
407 InorderBackEnd<Impl>::squash(const InstSeqNum &squash_num, const Addr &next_PC)
409 DPRINTF(IBE, "Squashing from [sn:%lli], setting PC to %#x\n",
410 squash_num, next_PC);
412 InstListIt squash_it = --(instList.end());
416 while (!instList.empty() && (*squash_it)->seqNum > squash_num) {
417 DynInstPtr inst = *squash_it;
419 DPRINTF(IBE, "Squashing instruction PC %#x, [sn:%lli].\n",
423 // May cause problems with misc regs
424 freed_regs+= inst->numDestRegs();
425 inst->clearDependents();
430 frontEnd->addFreeRegs(freed_regs);
432 for (int i = 0; i < latency+1; ++i) {
433 numInstsToWB.advance();
436 squashPending = false;
438 // Probably want to make sure that this squash is the one that set the
439 // thread into inSyscall mode.
440 thread->inSyscall = false;
442 // Tell front end to squash, reset PC to new one.
443 frontEnd->squash(squash_num, next_PC);
445 faultFromFetch = NULL;
448 template <class Impl>
450 InorderBackEnd<Impl>::squashFromXC()
452 // Record that I need to squash
453 squashPending = true;
455 thread->inSyscall = true;
458 template <class Impl>
460 InorderBackEnd<Impl>::setSquashInfoFromXC()
462 // Need to handle the case of the instList being empty. In that case
463 // probably any number works, except maybe with stores in the store buffer.
464 squashSeqNum = instList.empty() ? 0 : instList.front()->seqNum - 1;
466 squashNextPC = thread->PC;
469 template <class Impl>
471 InorderBackEnd<Impl>::fetchFault(Fault &fault)
473 faultFromFetch = fault;
476 template <class Impl>
478 InorderBackEnd<Impl>::dumpInsts()
483 InstListIt inst_list_it = instList.begin();
485 cprintf("Inst list size: %i\n", instList.size());
487 while (inst_list_it != instList.end())
489 cprintf("Instruction:%i\n",
491 if (!(*inst_list_it)->isSquashed()) {
492 if (!(*inst_list_it)->isIssued()) {
494 cprintf("Count:%i\n", valid_num);
495 } else if ((*inst_list_it)->isMemRef() &&
496 !(*inst_list_it)->memOpDone) {
497 // Loads that have not been marked as executed still count
498 // towards the total instructions.
500 cprintf("Count:%i\n", valid_num);
504 cprintf("PC:%#x\n[sn:%lli]\n[tid:%i]\n"
505 "Issued:%i\nSquashed:%i\n",
506 (*inst_list_it)->readPC(),
507 (*inst_list_it)->seqNum,
508 (*inst_list_it)->threadNumber,
509 (*inst_list_it)->isIssued(),
510 (*inst_list_it)->isSquashed());
512 if ((*inst_list_it)->isMemRef()) {
513 cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone);
523 template <class Impl>
524 InorderBackEnd<Impl>::DCacheCompletionEvent::DCacheCompletionEvent(
526 : Event(&mainEventQueue, CPU_Tick_Pri), be(_be)
528 // this->setFlags(Event::AutoDelete);
531 template <class Impl>
533 InorderBackEnd<Impl>::DCacheCompletionEvent::process()
536 be->status = DcacheMissComplete;
539 template <class Impl>
541 InorderBackEnd<Impl>::DCacheCompletionEvent::description() const
543 return "DCache completion";