42 #ifndef __CPU_CHECKER_CPU_IMPL_HH__
43 #define __CPU_CHECKER_CPU_IMPL_HH__
49 #include "config/the_isa.hh"
57 #include "debug/Checker.hh"
65 template <
class DynInstPtr>
71 fault->invoke(tc, curStaticInst);
72 thread->decoder.reset();
75 if (curStaticInst->isLastMicroop())
78 curStaticInst->advancePC(pcState);
79 thread->pcState(pcState);
86 template <
class DynInstPtr>
90 DPRINTF(
Checker,
"IRQ detected at PC: %s with %d insts in buffer\n",
91 thread->
pcState(), instList.size());
93 if (!instList.empty()) {
98 for (itr = instList.begin(); itr != instList.end(); itr++) {
99 (*itr)->setCompleted();
102 inst = instList.front();
103 boundaryInst = instList.back();
107 if ((!boundaryInst && curMacroStaticInst &&
108 curStaticInst->isDelayedCommit() &&
109 !curStaticInst->isLastMicroop()) ||
110 (boundaryInst && boundaryInst->isDelayedCommit() &&
111 !boundaryInst->isLastMicroop())) {
112 panic(
"%lli: Trying to take an interrupt in middle of "
113 "a non-interuptable instruction!",
curTick());
116 thread->decoder.reset();
120 template <
class DynInstPtr>
129 if ((completed_inst->isSerializing() ||
130 completed_inst->isSerializeBefore()) &&
132 (instList.front()->seqNum != completed_inst->seqNum) : 0)) {
133 panic(
"%lli: Instruction sn:%lli at PC %s is serializing before but is"
134 " entering instList with other instructions\n",
curTick(),
135 completed_inst->seqNum, completed_inst->pcState());
143 if (!instList.empty()) {
144 if (youngestSN < completed_inst->seqNum) {
146 completed_inst->seqNum, completed_inst->
pcState());
147 instList.push_back(completed_inst);
148 youngestSN = completed_inst->seqNum;
151 if (!instList.front()->isCompleted()) {
154 inst = instList.front();
155 instList.pop_front();
158 if (!completed_inst->isCompleted()) {
159 if (youngestSN < completed_inst->seqNum) {
161 completed_inst->seqNum, completed_inst->
pcState());
162 instList.push_back(completed_inst);
163 youngestSN = completed_inst->seqNum;
167 if (youngestSN < completed_inst->seqNum) {
168 inst = completed_inst;
169 youngestSN = completed_inst->seqNum;
178 if (inst->isSerializeAfter() && !instList.empty()) {
179 panic(
"%lli: Instruction sn:%lli at PC %s is serializing after but is"
180 " exiting instList with other instructions\n",
curTick(),
181 completed_inst->seqNum, completed_inst->pcState());
183 unverifiedInst = inst;
186 auto &
decoder = thread->decoder;
194 unverifiedInst->seqNum, unverifiedInst->
pcState());
195 unverifiedReq = NULL;
196 unverifiedReq = unverifiedInst->reqToVerify;
197 unverifiedMemData = unverifiedInst->memData;
199 while (!result.empty()) {
202 baseStats.numCycles++;
207 thread->setIntReg(zeroReg, 0);
216 if (newPCState == thread->pcState()) {
219 warn(
"%lli: Changed PC does not match expected PC, "
220 "changed: %s, expected: %s",
221 curTick(), thread->pcState(), newPCState);
224 willChangePC =
false;
230 uint64_t fetchOffset = 0;
231 bool fetchDone =
false;
233 Addr fetch_PC = thread->instAddr();
234 fetch_PC = (fetch_PC & pc_mask) + fetchOffset;
237 if (!curMacroStaticInst) {
239 auto mem_req = std::make_shared<Request>(
240 fetch_PC,
decoder.moreBytesSize(), 0, requestorId,
241 fetch_PC, thread->contextId());
243 mem_req->setVirt(fetch_PC,
decoder.moreBytesSize(),
247 fault = mmu->translateFunctional(
251 if (unverifiedInst->getFault() ==
NoFault) {
257 warn(
"%lli: Instruction PC %s was not found in the "
258 "ITB!",
curTick(), thread->pcState());
259 handleError(unverifiedInst);
265 unverifiedInst = NULL;
271 fault = unverifiedInst->getFault();
278 icachePort->sendFunctional(pkt);
289 curStaticInst =
decoder.fetchRomMicroop(
290 pcState.microPC(),
nullptr);
291 }
else if (!curMacroStaticInst) {
298 (pcState.instAddr() & pc_mask) + fetchOffset;
299 decoder.moreBytes(pcState, fetchPC);
306 instPtr =
decoder.decode(pcState);
307 thread->pcState(pcState);
310 fetchOffset +=
decoder.moreBytesSize();
316 curMacroStaticInst = instPtr;
320 curStaticInst = instPtr;
335 Fault unverifiedFault;
337 unverifiedFault = unverifiedInst->getFault();
341 validateInst(unverifiedInst);
353 if (!unverifiedInst->isUnverifiable()) {
359 fault = curStaticInst->execute(
this, traceData);
368 validateExecution(unverifiedInst);
370 if (curStaticInst->isLoad()) {
374 panic(
"%lli: sn: %lli at PC: %s took a fault in checker "
375 "but not in driver CPU\n",
curTick(),
376 unverifiedInst->seqNum, unverifiedInst->pcState());
378 panic(
"%lli: sn: %lli at PC: %s took a fault in driver "
379 "CPU but not in checker\n",
curTick(),
380 unverifiedInst->seqNum, unverifiedInst->pcState());
387 fault->invoke(tc, curStaticInst);
389 newPCState = thread->pcState();
404 oldpc = thread->instAddr();
405 thread->pcEventQueue.service(oldpc, tc);
407 }
while (oldpc != thread->instAddr());
410 newPCState = thread->pcState();
421 if (instList.empty()) {
423 }
else if (instList.front()->isCompleted()) {
424 unverifiedInst = NULL;
425 unverifiedInst = instList.front();
426 instList.pop_front();
431 unverifiedInst = NULL;
434 template <
class DynInstPtr>
441 template <
class DynInstPtr>
444 template <
class DynInstPtr>
448 if (inst->instAddr() != thread->instAddr()) {
449 warn(
"%lli: PCs do not match! Inst: %s, checker: %s",
450 curTick(), inst->pcState(), thread->pcState());
452 warn(
"%lli: Changed PCs recently, may not be an error",
459 if (curStaticInst != inst->staticInst) {
460 warn(
"%lli: StaticInstPtrs don't match. (%s, %s).\n",
curTick(),
461 curStaticInst->getName(), inst->staticInst->getName());
465 template <
class DynInstPtr>
472 bool result_mismatch =
false;
473 bool scalar_mismatch =
false;
474 bool vector_mismatch =
false;
476 if (inst->isUnverifiable()) {
481 }
else if (inst->numDestRegs() > 0 && !result.empty()) {
482 DPRINTF(
Checker,
"Dest regs %d, number of checker dest regs %d\n",
483 inst->numDestRegs(), result.size());
484 for (
int i = 0;
i < inst->numDestRegs() && !result.empty();
i++) {
485 checker_val = result.front();
487 inst_val = inst->popResult(
489 if (checker_val != inst_val) {
490 result_mismatch =
true;
492 scalar_mismatch = checker_val.
isScalar();
493 vector_mismatch = checker_val.
isVector();
494 panic_if(!(scalar_mismatch || vector_mismatch),
495 "Unknown type of result\n");
504 if (result_mismatch) {
505 if (scalar_mismatch) {
506 warn(
"%lli: Instruction results (%i) do not match! (Values may"
507 " not actually be integers) Inst: %#x, checker: %#x",
519 if (inst->isLoad() && warnOnlyOnLoadError) {
520 copyResult(inst, inst_val, idx);
526 if (inst->nextInstAddr() != thread->nextInstAddr()) {
527 warn(
"%lli: Instruction next PCs do not match! Inst: %#x, "
529 curTick(), inst->nextInstAddr(), thread->nextInstAddr());
538 while (!miscRegIdxs.empty()) {
539 int misc_reg_idx = miscRegIdxs.front();
542 if (inst->tcBase()->readMiscRegNoEffect(misc_reg_idx) !=
543 thread->readMiscRegNoEffect(misc_reg_idx)) {
544 warn(
"%lli: Misc reg idx %i (side effect) does not match! "
545 "Inst: %#x, checker: %#x",
547 inst->tcBase()->readMiscRegNoEffect(misc_reg_idx),
548 thread->readMiscRegNoEffect(misc_reg_idx));
558 template <
class DynInstPtr>
562 if (updateThisCycle) {
564 panic(
"%lli: Instruction PC %#x results didn't match up, copying all "
565 "registers from main CPU",
curTick(), unverifiedInst->instAddr());
568 bool no_squash_from_TC = unverifiedInst->thread->noSquashFromTC;
569 unverifiedInst->thread->noSquashFromTC =
true;
572 thread->copyArchRegs(unverifiedInst->tcBase());
573 unverifiedInst->thread->noSquashFromTC = no_squash_from_TC;
576 curStaticInst = unverifiedInst->staticInst;
579 updateThisCycle =
false;
583 template <
class DynInstPtr>
590 if (start_idx >= 0) {
591 const RegId& idx = inst->destRegIdx(start_idx);
603 thread->setVecReg(idx, mismatch_val.
asVector());
607 "Unexpected type of result");
624 for (
int i = start_idx;
i < inst->numDestRegs();
i++) {
625 const RegId& idx = inst->destRegIdx(
i);
626 res = inst->popResult();
638 thread->setVecReg(idx, res.
asVector());
651 thread->setMiscReg(idx.
index(), 0);
660 template <
class DynInstPtr>
664 cprintf(
"Error detected, instruction information:\n");
665 cprintf(
"PC:%s, nextPC:%#x\n[sn:%lli]\n[tid:%i]\n"
668 inst->nextInstAddr(),
671 inst->isCompleted());
676 template <
class DynInstPtr>
684 cprintf(
"Inst list size: %i\n", instList.size());
686 while (inst_list_it != instList.end())
691 cprintf(
"PC:%s\n[sn:%lli]\n[tid:%i]\n"
693 (*inst_list_it)->pcState(),
694 (*inst_list_it)->seqNum,
695 (*inst_list_it)->threadNumber,
696 (*inst_list_it)->isCompleted());
708 #endif//__CPU_CHECKER_CPU_IMPL_HH__