cpu_impl.hh revision 9918:2c7219e2d999
16129Snate@binkert.org/* 26129Snate@binkert.org * Copyright (c) 2011 ARM Limited 36129Snate@binkert.org * Copyright (c) 2013 Advanced Micro Devices, Inc. 46129Snate@binkert.org * All rights reserved 56129Snate@binkert.org * 66129Snate@binkert.org * The license below extends only to copyright in the software and shall 76129Snate@binkert.org * not be construed as granting a license to any other intellectual 86129Snate@binkert.org * property including but not limited to intellectual property relating 96129Snate@binkert.org * to a hardware implementation of the functionality of the software 106129Snate@binkert.org * licensed hereunder. You may use the software subject to the license 116129Snate@binkert.org * terms below provided that you ensure that this notice is replicated 126129Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 136129Snate@binkert.org * modified or unmodified, in source code or in binary form. 146129Snate@binkert.org * 156129Snate@binkert.org * Copyright (c) 2006 The Regents of The University of Michigan 166129Snate@binkert.org * All rights reserved. 176129Snate@binkert.org * 186129Snate@binkert.org * Redistribution and use in source and binary forms, with or without 196129Snate@binkert.org * modification, are permitted provided that the following conditions are 206129Snate@binkert.org * met: redistributions of source code must retain the above copyright 216129Snate@binkert.org * notice, this list of conditions and the following disclaimer; 226129Snate@binkert.org * redistributions in binary form must reproduce the above copyright 236129Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 246129Snate@binkert.org * documentation and/or other materials provided with the distribution; 256129Snate@binkert.org * neither the name of the copyright holders nor the names of its 266129Snate@binkert.org * contributors may be used to endorse or promote products derived from 276129Snate@binkert.org * this software without specific prior written permission. 286129Snate@binkert.org * 296129Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 306129Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 316169Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 326169Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 336169Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 348229Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 356130Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 366129Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 376129Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 386129Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3914266Sandreas.sandberg@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4014266Sandreas.sandberg@arm.com * 416130Snate@binkert.org * Authors: Kevin Lim 426130Snate@binkert.org * Geoffrey Blake 436130Snate@binkert.org */ 446130Snate@binkert.org 456130Snate@binkert.org#include <list> 466130Snate@binkert.org#include <string> 476130Snate@binkert.org 486130Snate@binkert.org#include "arch/isa_traits.hh" 497462Snate@binkert.org#include "arch/vtophys.hh" 506130Snate@binkert.org#include "base/refcnt.hh" 516130Snate@binkert.org#include "config/the_isa.hh" 526130Snate@binkert.org#include "cpu/base_dyn_inst.hh" 536130Snate@binkert.org#include "cpu/exetrace.hh" 546130Snate@binkert.org#include "cpu/reg_class.hh" 556130Snate@binkert.org#include "cpu/simple_thread.hh" 566130Snate@binkert.org#include "cpu/static_inst.hh" 576130Snate@binkert.org#include "cpu/thread_context.hh" 586130Snate@binkert.org#include "cpu/checker/cpu.hh" 596130Snate@binkert.org#include "debug/Checker.hh" 606130Snate@binkert.org#include "sim/full_system.hh" 616130Snate@binkert.org#include "sim/sim_object.hh" 629743Snilay@cs.wisc.edu#include "sim/stats.hh" 639743Snilay@cs.wisc.edu 646130Snate@binkert.orgusing namespace std; 656130Snate@binkert.orgusing namespace TheISA; 667462Snate@binkert.org 676130Snate@binkert.orgtemplate <class Impl> 687505Snate@binkert.orgvoid 698296Snate@binkert.orgChecker<Impl>::advancePC(Fault fault) 706129Snate@binkert.org{ 716129Snate@binkert.org if (fault != NoFault) { 726129Snate@binkert.org curMacroStaticInst = StaticInst::nullStaticInstPtr; 736129Snate@binkert.org fault->invoke(tc, curStaticInst); 746129Snate@binkert.org thread->decoder.reset(); 756129Snate@binkert.org } else { 768243Sbradley.danofsky@amd.com if (curStaticInst) { 778243Sbradley.danofsky@amd.com if (curStaticInst->isLastMicroop()) 786129Snate@binkert.org curMacroStaticInst = StaticInst::nullStaticInstPtr; 796129Snate@binkert.org TheISA::PCState pcState = thread->pcState(); 806129Snate@binkert.org TheISA::advancePC(pcState, curStaticInst); 816130Snate@binkert.org thread->pcState(pcState); 826129Snate@binkert.org DPRINTF(Checker, "Advancing PC to %s.\n", thread->pcState()); 836129Snate@binkert.org } 846129Snate@binkert.org } 856129Snate@binkert.org} 866129Snate@binkert.org////////////////////////////////////////////////// 876129Snate@binkert.org 886129Snate@binkert.orgtemplate <class Impl> 896129Snate@binkert.orgvoid 906129Snate@binkert.orgChecker<Impl>::handlePendingInt() 916129Snate@binkert.org{ 926129Snate@binkert.org DPRINTF(Checker, "IRQ detected at PC: %s with %d insts in buffer\n", 936129Snate@binkert.org thread->pcState(), instList.size()); 946129Snate@binkert.org DynInstPtr boundaryInst = NULL; 956129Snate@binkert.org if (!instList.empty()) { 966129Snate@binkert.org // Set the instructions as completed and verify as much as possible. 976129Snate@binkert.org DynInstPtr inst; 986129Snate@binkert.org typename std::list<DynInstPtr>::iterator itr; 996129Snate@binkert.org 1006129Snate@binkert.org for (itr = instList.begin(); itr != instList.end(); itr++) { 1016129Snate@binkert.org (*itr)->setCompleted(); 10214266Sandreas.sandberg@arm.com } 1038243Sbradley.danofsky@amd.com 1046129Snate@binkert.org inst = instList.front(); 1056129Snate@binkert.org boundaryInst = instList.back(); 1066129Snate@binkert.org verify(inst); // verify the instructions 1076129Snate@binkert.org inst = NULL; 1086129Snate@binkert.org } 1096129Snate@binkert.org if ((!boundaryInst && curMacroStaticInst && 1106129Snate@binkert.org curStaticInst->isDelayedCommit() && 1116129Snate@binkert.org !curStaticInst->isLastMicroop()) || 1126129Snate@binkert.org (boundaryInst && boundaryInst->isDelayedCommit() && 1136129Snate@binkert.org !boundaryInst->isLastMicroop())) { 1146129Snate@binkert.org panic("%lli: Trying to take an interrupt in middle of " 1156129Snate@binkert.org "a non-interuptable instruction!", curTick()); 1166129Snate@binkert.org } 1176129Snate@binkert.org boundaryInst = NULL; 1186129Snate@binkert.org thread->decoder.reset(); 1196129Snate@binkert.org curMacroStaticInst = StaticInst::nullStaticInstPtr; 1206129Snate@binkert.org} 1216129Snate@binkert.org 1226129Snate@binkert.orgtemplate <class Impl> 1236129Snate@binkert.orgvoid 1246129Snate@binkert.orgChecker<Impl>::verify(DynInstPtr &completed_inst) 1256129Snate@binkert.org{ 1266129Snate@binkert.org DynInstPtr inst; 1276129Snate@binkert.org 1286129Snate@binkert.org // Make sure serializing instructions are actually 1296129Snate@binkert.org // seen as serializing to commit. instList should be 1306129Snate@binkert.org // empty in these cases. 1316129Snate@binkert.org if ((completed_inst->isSerializing() || 1326129Snate@binkert.org completed_inst->isSerializeBefore()) && 1336129Snate@binkert.org (!instList.empty() ? 1346129Snate@binkert.org (instList.front()->seqNum != completed_inst->seqNum) : 0)) { 1356129Snate@binkert.org panic("%lli: Instruction sn:%lli at PC %s is serializing before but is" 1366129Snate@binkert.org " entering instList with other instructions\n", curTick(), 1378296Snate@binkert.org completed_inst->seqNum, completed_inst->pcState()); 1386129Snate@binkert.org } 1396129Snate@binkert.org 1406129Snate@binkert.org // Either check this instruction, or add it to a list of 1416129Snate@binkert.org // instructions waiting to be checked. Instructions must be 1426129Snate@binkert.org // checked in program order, so if a store has committed yet not 1436129Snate@binkert.org // completed, there may be some instructions that are waiting 1446129Snate@binkert.org // behind it that have completed and must be checked. 1456129Snate@binkert.org if (!instList.empty()) { 1466129Snate@binkert.org if (youngestSN < completed_inst->seqNum) { 1476129Snate@binkert.org DPRINTF(Checker, "Adding instruction [sn:%lli] PC:%s to list\n", 1486129Snate@binkert.org completed_inst->seqNum, completed_inst->pcState()); 1496129Snate@binkert.org instList.push_back(completed_inst); 1506129Snate@binkert.org youngestSN = completed_inst->seqNum; 1516129Snate@binkert.org } 1526129Snate@binkert.org 1536129Snate@binkert.org if (!instList.front()->isCompleted()) { 1546129Snate@binkert.org return; 1556129Snate@binkert.org } else { 1566129Snate@binkert.org inst = instList.front(); 1576129Snate@binkert.org instList.pop_front(); 1586129Snate@binkert.org } 1596129Snate@binkert.org } else { 1606129Snate@binkert.org if (!completed_inst->isCompleted()) { 1616129Snate@binkert.org if (youngestSN < completed_inst->seqNum) { 1626129Snate@binkert.org DPRINTF(Checker, "Adding instruction [sn:%lli] PC:%s to list\n", 1636129Snate@binkert.org completed_inst->seqNum, completed_inst->pcState()); 1646129Snate@binkert.org instList.push_back(completed_inst); 1656129Snate@binkert.org youngestSN = completed_inst->seqNum; 1666129Snate@binkert.org } 1676129Snate@binkert.org return; 1686129Snate@binkert.org } else { 1696129Snate@binkert.org if (youngestSN < completed_inst->seqNum) { 1706129Snate@binkert.org inst = completed_inst; 1716129Snate@binkert.org youngestSN = completed_inst->seqNum; 1726129Snate@binkert.org } else { 1736129Snate@binkert.org return; 1746129Snate@binkert.org } 1757831Snate@binkert.org } 1767505Snate@binkert.org } 1776129Snate@binkert.org 1786129Snate@binkert.org // Make sure a serializing instruction is actually seen as 1797505Snate@binkert.org // serializing. instList should be empty here 1807505Snate@binkert.org if (inst->isSerializeAfter() && !instList.empty()) { 1817505Snate@binkert.org panic("%lli: Instruction sn:%lli at PC %s is serializing after but is" 1827505Snate@binkert.org " exiting instList with other instructions\n", curTick(), 1837505Snate@binkert.org completed_inst->seqNum, completed_inst->pcState()); 1846129Snate@binkert.org } 1856129Snate@binkert.org unverifiedInst = inst; 1866129Snate@binkert.org inst = NULL; 1876129Snate@binkert.org 1886129Snate@binkert.org // Try to check all instructions that are completed, ending if we 1896129Snate@binkert.org // run out of instructions to check or if an instruction is not 1906129Snate@binkert.org // yet completed. 1918666SPrakash.Ramrakhyani@arm.com while (1) { 1926129Snate@binkert.org DPRINTF(Checker, "Processing instruction [sn:%lli] PC:%s.\n", 1936129Snate@binkert.org unverifiedInst->seqNum, unverifiedInst->pcState()); 1946129Snate@binkert.org unverifiedReq = NULL; 1956129Snate@binkert.org unverifiedReq = unverifiedInst->reqToVerify; 1966129Snate@binkert.org unverifiedMemData = unverifiedInst->memData; 1976129Snate@binkert.org // Make sure results queue is empty 1986129Snate@binkert.org while (!result.empty()) { 1996129Snate@binkert.org result.pop(); 2006129Snate@binkert.org } 2016129Snate@binkert.org numCycles++; 2026129Snate@binkert.org 2036129Snate@binkert.org Fault fault = NoFault; 2046129Snate@binkert.org 2056129Snate@binkert.org // maintain $r0 semantics 2066129Snate@binkert.org thread->setIntReg(ZeroReg, 0); 2076129Snate@binkert.org#if THE_ISA == ALPHA_ISA 2086129Snate@binkert.org thread->setFloatReg(ZeroReg, 0.0); 2096129Snate@binkert.org#endif 2106129Snate@binkert.org 2116129Snate@binkert.org // Check if any recent PC changes match up with anything we 2126129Snate@binkert.org // expect to happen. This is mostly to check if traps or 2136129Snate@binkert.org // PC-based events have occurred in both the checker and CPU. 2146129Snate@binkert.org if (changedPC) { 2156129Snate@binkert.org DPRINTF(Checker, "Changed PC recently to %s\n", 2166129Snate@binkert.org thread->pcState()); 2176129Snate@binkert.org if (willChangePC) { 2186129Snate@binkert.org if (newPCState == thread->pcState()) { 2196129Snate@binkert.org DPRINTF(Checker, "Changed PC matches expected PC\n"); 2206129Snate@binkert.org } else { 2216129Snate@binkert.org warn("%lli: Changed PC does not match expected PC, " 2226129Snate@binkert.org "changed: %s, expected: %s", 2236129Snate@binkert.org curTick(), thread->pcState(), newPCState); 2246129Snate@binkert.org CheckerCPU::handleError(); 2256129Snate@binkert.org } 2266129Snate@binkert.org willChangePC = false; 2276129Snate@binkert.org } 2286129Snate@binkert.org changedPC = false; 2296129Snate@binkert.org } 2306129Snate@binkert.org if (changedNextPC) { 2316129Snate@binkert.org DPRINTF(Checker, "Changed NextPC recently to %#x\n", 2326129Snate@binkert.org thread->nextInstAddr()); 2336129Snate@binkert.org changedNextPC = false; 2346129Snate@binkert.org } 23511565Sdavid.guillen@arm.com 23611565Sdavid.guillen@arm.com // Try to fetch the instruction 2376129Snate@binkert.org uint64_t fetchOffset = 0; 2386129Snate@binkert.org bool fetchDone = false; 2396129Snate@binkert.org 2406129Snate@binkert.org while (!fetchDone) { 2416129Snate@binkert.org Addr fetch_PC = thread->instAddr(); 2426129Snate@binkert.org fetch_PC = (fetch_PC & PCMask) + fetchOffset; 2436129Snate@binkert.org 2446129Snate@binkert.org MachInst machInst; 2458514SThomas.Grass@ARM.com 2468514SThomas.Grass@ARM.com // If not in the middle of a macro instruction 2478514SThomas.Grass@ARM.com if (!curMacroStaticInst) { 2488514SThomas.Grass@ARM.com // set up memory request for instruction fetch 2498514SThomas.Grass@ARM.com memReq = new Request(unverifiedInst->threadNumber, fetch_PC, 2508514SThomas.Grass@ARM.com sizeof(MachInst), 2518514SThomas.Grass@ARM.com 0, 2528514SThomas.Grass@ARM.com masterId, 2538514SThomas.Grass@ARM.com fetch_PC, thread->contextId(), 2548514SThomas.Grass@ARM.com unverifiedInst->threadNumber); 2558514SThomas.Grass@ARM.com memReq->setVirt(0, fetch_PC, sizeof(MachInst), 2568514SThomas.Grass@ARM.com Request::INST_FETCH, masterId, thread->instAddr()); 2578514SThomas.Grass@ARM.com 2588514SThomas.Grass@ARM.com 2596129Snate@binkert.org fault = itb->translateFunctional(memReq, tc, BaseTLB::Execute); 2607811Ssteve.reinhardt@amd.com 2616169Snate@binkert.org if (fault != NoFault) { 2626169Snate@binkert.org if (unverifiedInst->getFault() == NoFault) { 263 // In this case the instruction was not a dummy 264 // instruction carrying an ITB fault. In the single 265 // threaded case the ITB should still be able to 266 // translate this instruction; in the SMT case it's 267 // possible that its ITB entry was kicked out. 268 warn("%lli: Instruction PC %s was not found in the " 269 "ITB!", curTick(), thread->pcState()); 270 handleError(unverifiedInst); 271 272 // go to the next instruction 273 advancePC(NoFault); 274 275 // Give up on an ITB fault.. 276 delete memReq; 277 unverifiedInst = NULL; 278 return; 279 } else { 280 // The instruction is carrying an ITB fault. Handle 281 // the fault and see if our results match the CPU on 282 // the next tick(). 283 fault = unverifiedInst->getFault(); 284 delete memReq; 285 break; 286 } 287 } else { 288 PacketPtr pkt = new Packet(memReq, MemCmd::ReadReq); 289 290 pkt->dataStatic(&machInst); 291 icachePort->sendFunctional(pkt); 292 machInst = gtoh(machInst); 293 294 delete memReq; 295 delete pkt; 296 } 297 } 298 299 if (fault == NoFault) { 300 TheISA::PCState pcState = thread->pcState(); 301 302 if (isRomMicroPC(pcState.microPC())) { 303 fetchDone = true; 304 curStaticInst = 305 microcodeRom.fetchMicroop(pcState.microPC(), NULL); 306 } else if (!curMacroStaticInst) { 307 //We're not in the middle of a macro instruction 308 StaticInstPtr instPtr = NULL; 309 310 //Predecode, ie bundle up an ExtMachInst 311 //If more fetch data is needed, pass it in. 312 Addr fetchPC = (pcState.instAddr() & PCMask) + fetchOffset; 313 thread->decoder.moreBytes(pcState, fetchPC, machInst); 314 315 //If an instruction is ready, decode it. 316 //Otherwise, we'll have to fetch beyond the 317 //MachInst at the current pc. 318 if (thread->decoder.instReady()) { 319 fetchDone = true; 320 instPtr = thread->decoder.decode(pcState); 321 thread->pcState(pcState); 322 } else { 323 fetchDone = false; 324 fetchOffset += sizeof(TheISA::MachInst); 325 } 326 327 //If we decoded an instruction and it's microcoded, 328 //start pulling out micro ops 329 if (instPtr && instPtr->isMacroop()) { 330 curMacroStaticInst = instPtr; 331 curStaticInst = 332 instPtr->fetchMicroop(pcState.microPC()); 333 } else { 334 curStaticInst = instPtr; 335 } 336 } else { 337 // Read the next micro op from the macro-op 338 curStaticInst = 339 curMacroStaticInst->fetchMicroop(pcState.microPC()); 340 fetchDone = true; 341 } 342 } 343 } 344 // reset decoder on Checker 345 thread->decoder.reset(); 346 347 // Check Checker and CPU get same instruction, and record 348 // any faults the CPU may have had. 349 Fault unverifiedFault; 350 if (fault == NoFault) { 351 unverifiedFault = unverifiedInst->getFault(); 352 353 // Checks that the instruction matches what we expected it to be. 354 // Checks both the machine instruction and the PC. 355 validateInst(unverifiedInst); 356 } 357 358 // keep an instruction count 359 numInst++; 360 361 362 // Either the instruction was a fault and we should process the fault, 363 // or we should just go ahead execute the instruction. This assumes 364 // that the instruction is properly marked as a fault. 365 if (fault == NoFault) { 366 // Execute Checker instruction and trace 367 if (!unverifiedInst->isUnverifiable()) { 368 Trace::InstRecord *traceData = tracer->getInstRecord(curTick(), 369 tc, 370 curStaticInst, 371 pcState(), 372 curMacroStaticInst); 373 fault = curStaticInst->execute(this, traceData); 374 if (traceData) { 375 traceData->dump(); 376 delete traceData; 377 } 378 } 379 380 if (fault == NoFault && unverifiedFault == NoFault) { 381 thread->funcExeInst++; 382 // Checks to make sure instrution results are correct. 383 validateExecution(unverifiedInst); 384 385 if (curStaticInst->isLoad()) { 386 ++numLoad; 387 } 388 } else if (fault != NoFault && unverifiedFault == NoFault) { 389 panic("%lli: sn: %lli at PC: %s took a fault in checker " 390 "but not in driver CPU\n", curTick(), 391 unverifiedInst->seqNum, unverifiedInst->pcState()); 392 } else if (fault == NoFault && unverifiedFault != NoFault) { 393 panic("%lli: sn: %lli at PC: %s took a fault in driver " 394 "CPU but not in checker\n", curTick(), 395 unverifiedInst->seqNum, unverifiedInst->pcState()); 396 } 397 } 398 399 // Take any faults here 400 if (fault != NoFault) { 401 if (FullSystem) { 402 fault->invoke(tc, curStaticInst); 403 willChangePC = true; 404 newPCState = thread->pcState(); 405 DPRINTF(Checker, "Fault, PC is now %s\n", newPCState); 406 curMacroStaticInst = StaticInst::nullStaticInstPtr; 407 } 408 } else { 409 advancePC(fault); 410 } 411 412 if (FullSystem) { 413 // @todo: Determine if these should happen only if the 414 // instruction hasn't faulted. In the SimpleCPU case this may 415 // not be true, but in the O3 or Ozone case this may be true. 416 Addr oldpc; 417 int count = 0; 418 do { 419 oldpc = thread->instAddr(); 420 system->pcEventQueue.service(tc); 421 count++; 422 } while (oldpc != thread->instAddr()); 423 if (count > 1) { 424 willChangePC = true; 425 newPCState = thread->pcState(); 426 DPRINTF(Checker, "PC Event, PC is now %s\n", newPCState); 427 } 428 } 429 430 // @todo: Optionally can check all registers. (Or just those 431 // that have been modified). 432 validateState(); 433 434 // Continue verifying instructions if there's another completed 435 // instruction waiting to be verified. 436 if (instList.empty()) { 437 break; 438 } else if (instList.front()->isCompleted()) { 439 unverifiedInst = NULL; 440 unverifiedInst = instList.front(); 441 instList.pop_front(); 442 } else { 443 break; 444 } 445 } 446 unverifiedInst = NULL; 447} 448 449template <class Impl> 450void 451Checker<Impl>::switchOut() 452{ 453 instList.clear(); 454} 455 456template <class Impl> 457void 458Checker<Impl>::takeOverFrom(BaseCPU *oldCPU) 459{ 460} 461 462template <class Impl> 463void 464Checker<Impl>::validateInst(DynInstPtr &inst) 465{ 466 if (inst->instAddr() != thread->instAddr()) { 467 warn("%lli: PCs do not match! Inst: %s, checker: %s", 468 curTick(), inst->pcState(), thread->pcState()); 469 if (changedPC) { 470 warn("%lli: Changed PCs recently, may not be an error", 471 curTick()); 472 } else { 473 handleError(inst); 474 } 475 } 476 477 if (curStaticInst != inst->staticInst) { 478 warn("%lli: StaticInstPtrs don't match. (%s, %s).\n", curTick(), 479 curStaticInst->getName(), inst->staticInst->getName()); 480 } 481} 482 483template <class Impl> 484void 485Checker<Impl>::validateExecution(DynInstPtr &inst) 486{ 487 uint64_t checker_val; 488 uint64_t inst_val; 489 int idx = -1; 490 bool result_mismatch = false; 491 492 if (inst->isUnverifiable()) { 493 // Unverifiable instructions assume they were executed 494 // properly by the CPU. Grab the result from the 495 // instruction and write it to the register. 496 copyResult(inst, 0, idx); 497 } else if (inst->numDestRegs() > 0 && !result.empty()) { 498 DPRINTF(Checker, "Dest regs %d, number of checker dest regs %d\n", 499 inst->numDestRegs(), result.size()); 500 for (int i = 0; i < inst->numDestRegs() && !result.empty(); i++) { 501 result.front().get(checker_val); 502 result.pop(); 503 inst_val = 0; 504 inst->template popResult<uint64_t>(inst_val); 505 if (checker_val != inst_val) { 506 result_mismatch = true; 507 idx = i; 508 break; 509 } 510 } 511 } // Checker CPU checks all the saved results in the dyninst passed by 512 // the cpu model being checked against the saved results present in 513 // the static inst executed in the Checker. Sometimes the number 514 // of saved results differs between the dyninst and static inst, but 515 // this is ok and not a bug. May be worthwhile to try and correct this. 516 517 if (result_mismatch) { 518 warn("%lli: Instruction results do not match! (Values may not " 519 "actually be integers) Inst: %#x, checker: %#x", 520 curTick(), inst_val, checker_val); 521 522 // It's useful to verify load values from memory, but in MP 523 // systems the value obtained at execute may be different than 524 // the value obtained at completion. Similarly DMA can 525 // present the same problem on even UP systems. Thus there is 526 // the option to only warn on loads having a result error. 527 // The load/store queue in Detailed CPU can also cause problems 528 // if load/store forwarding is allowed. 529 if (inst->isLoad() && warnOnlyOnLoadError) { 530 copyResult(inst, inst_val, idx); 531 } else { 532 handleError(inst); 533 } 534 } 535 536 if (inst->nextInstAddr() != thread->nextInstAddr()) { 537 warn("%lli: Instruction next PCs do not match! Inst: %#x, " 538 "checker: %#x", 539 curTick(), inst->nextInstAddr(), thread->nextInstAddr()); 540 handleError(inst); 541 } 542 543 // Checking side effect registers can be difficult if they are not 544 // checked simultaneously with the execution of the instruction. 545 // This is because other valid instructions may have modified 546 // these registers in the meantime, and their values are not 547 // stored within the DynInst. 548 while (!miscRegIdxs.empty()) { 549 int misc_reg_idx = miscRegIdxs.front(); 550 miscRegIdxs.pop(); 551 552 if (inst->tcBase()->readMiscRegNoEffect(misc_reg_idx) != 553 thread->readMiscRegNoEffect(misc_reg_idx)) { 554 warn("%lli: Misc reg idx %i (side effect) does not match! " 555 "Inst: %#x, checker: %#x", 556 curTick(), misc_reg_idx, 557 inst->tcBase()->readMiscRegNoEffect(misc_reg_idx), 558 thread->readMiscRegNoEffect(misc_reg_idx)); 559 handleError(inst); 560 } 561 } 562} 563 564 565// This function is weird, if it is called it means the Checker and 566// O3 have diverged, so panic is called for now. It may be useful 567// to resynch states and continue if the divergence is a false positive 568template <class Impl> 569void 570Checker<Impl>::validateState() 571{ 572 if (updateThisCycle) { 573 // Change this back to warn if divergences end up being false positives 574 panic("%lli: Instruction PC %#x results didn't match up, copying all " 575 "registers from main CPU", curTick(), unverifiedInst->instAddr()); 576 577 // Terribly convoluted way to make sure O3 model does not implode 578 bool no_squash_from_TC = unverifiedInst->thread->noSquashFromTC; 579 unverifiedInst->thread->noSquashFromTC = true; 580 581 // Heavy-weight copying of all registers 582 thread->copyArchRegs(unverifiedInst->tcBase()); 583 unverifiedInst->thread->noSquashFromTC = no_squash_from_TC; 584 585 // Set curStaticInst to unverifiedInst->staticInst 586 curStaticInst = unverifiedInst->staticInst; 587 // Also advance the PC. Hopefully no PC-based events happened. 588 advancePC(NoFault); 589 updateThisCycle = false; 590 } 591} 592 593template <class Impl> 594void 595Checker<Impl>::copyResult(DynInstPtr &inst, uint64_t mismatch_val, 596 int start_idx) 597{ 598 // We've already popped one dest off the queue, 599 // so do the fix-up then start with the next dest reg; 600 if (start_idx >= 0) { 601 RegIndex idx = inst->destRegIdx(start_idx); 602 switch (regIdxToClass(idx)) { 603 case IntRegClass: 604 thread->setIntReg(idx, mismatch_val); 605 break; 606 case FloatRegClass: 607 thread->setFloatRegBits(idx, mismatch_val); 608 break; 609 case MiscRegClass: 610 thread->setMiscReg(idx - TheISA::Misc_Reg_Base, 611 mismatch_val); 612 break; 613 } 614 } 615 start_idx++; 616 uint64_t res = 0; 617 for (int i = start_idx; i < inst->numDestRegs(); i++) { 618 RegIndex idx = inst->destRegIdx(i); 619 inst->template popResult<uint64_t>(res); 620 switch (regIdxToClass(idx)) { 621 case IntRegClass: 622 thread->setIntReg(idx, res); 623 break; 624 case FloatRegClass: 625 thread->setFloatRegBits(idx, res); 626 break; 627 case MiscRegClass: 628 // Try to get the proper misc register index for ARM here... 629 thread->setMiscReg(idx - TheISA::Misc_Reg_Base, res); 630 break; 631 // else Register is out of range... 632 } 633 } 634} 635 636template <class Impl> 637void 638Checker<Impl>::dumpAndExit(DynInstPtr &inst) 639{ 640 cprintf("Error detected, instruction information:\n"); 641 cprintf("PC:%s, nextPC:%#x\n[sn:%lli]\n[tid:%i]\n" 642 "Completed:%i\n", 643 inst->pcState(), 644 inst->nextInstAddr(), 645 inst->seqNum, 646 inst->threadNumber, 647 inst->isCompleted()); 648 inst->dump(); 649 CheckerCPU::dumpAndExit(); 650} 651 652template <class Impl> 653void 654Checker<Impl>::dumpInsts() 655{ 656 int num = 0; 657 658 InstListIt inst_list_it = --(instList.end()); 659 660 cprintf("Inst list size: %i\n", instList.size()); 661 662 while (inst_list_it != instList.end()) 663 { 664 cprintf("Instruction:%i\n", 665 num); 666 667 cprintf("PC:%s\n[sn:%lli]\n[tid:%i]\n" 668 "Completed:%i\n", 669 (*inst_list_it)->pcState(), 670 (*inst_list_it)->seqNum, 671 (*inst_list_it)->threadNumber, 672 (*inst_list_it)->isCompleted()); 673 674 cprintf("\n"); 675 676 inst_list_it--; 677 ++num; 678 } 679 680} 681