cpu_impl.hh revision 8733
12315SN/A/* 28733Sgeoffrey.blake@arm.com * Copyright (c) 2011 ARM Limited 38733Sgeoffrey.blake@arm.com * All rights reserved 48733Sgeoffrey.blake@arm.com * 58733Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall 68733Sgeoffrey.blake@arm.com * not be construed as granting a license to any other intellectual 78733Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating 88733Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software 98733Sgeoffrey.blake@arm.com * licensed hereunder. You may use the software subject to the license 108733Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated 118733Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software, 128733Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form. 138733Sgeoffrey.blake@arm.com * 142332SN/A * Copyright (c) 2006 The Regents of The University of Michigan 152315SN/A * All rights reserved. 162315SN/A * 172315SN/A * Redistribution and use in source and binary forms, with or without 182315SN/A * modification, are permitted provided that the following conditions are 192315SN/A * met: redistributions of source code must retain the above copyright 202315SN/A * notice, this list of conditions and the following disclaimer; 212315SN/A * redistributions in binary form must reproduce the above copyright 222315SN/A * notice, this list of conditions and the following disclaimer in the 232315SN/A * documentation and/or other materials provided with the distribution; 242315SN/A * neither the name of the copyright holders nor the names of its 252315SN/A * contributors may be used to endorse or promote products derived from 262315SN/A * this software without specific prior written permission. 272315SN/A * 282315SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292315SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302315SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312315SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322315SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332315SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342315SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352315SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362315SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372315SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382315SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392689SN/A * 402689SN/A * Authors: Kevin Lim 418733Sgeoffrey.blake@arm.com * Geoffrey Blake 422315SN/A */ 432315SN/A 442315SN/A#include <list> 452315SN/A#include <string> 462315SN/A 472315SN/A#include "base/refcnt.hh" 486658Snate@binkert.org#include "config/the_isa.hh" 492315SN/A#include "cpu/base_dyn_inst.hh" 508733Sgeoffrey.blake@arm.com#include "cpu/exetrace.hh" 512683SN/A#include "cpu/simple_thread.hh" 528229Snate@binkert.org#include "cpu/static_inst.hh" 532680SN/A#include "cpu/thread_context.hh" 548733Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 558733Sgeoffrey.blake@arm.com#include "debug/Checker.hh" 562315SN/A#include "sim/sim_object.hh" 572315SN/A#include "sim/stats.hh" 582315SN/A 592315SN/A#if FULL_SYSTEM 602315SN/A#include "arch/vtophys.hh" 612315SN/A#endif // FULL_SYSTEM 622315SN/A 632315SN/Ausing namespace std; 648733Sgeoffrey.blake@arm.comusing namespace TheISA; 652315SN/A 668733Sgeoffrey.blake@arm.comtemplate <class Impl> 672315SN/Avoid 688733Sgeoffrey.blake@arm.comChecker<Impl>::advancePC(Fault fault) 698733Sgeoffrey.blake@arm.com{ 708733Sgeoffrey.blake@arm.com if (fault != NoFault) { 718733Sgeoffrey.blake@arm.com curMacroStaticInst = StaticInst::nullStaticInstPtr; 728733Sgeoffrey.blake@arm.com fault->invoke(tc, curStaticInst); 738733Sgeoffrey.blake@arm.com predecoder.reset(); 748733Sgeoffrey.blake@arm.com } else { 758733Sgeoffrey.blake@arm.com if (curStaticInst) { 768733Sgeoffrey.blake@arm.com if (curStaticInst->isLastMicroop()) 778733Sgeoffrey.blake@arm.com curMacroStaticInst = StaticInst::nullStaticInstPtr; 788733Sgeoffrey.blake@arm.com TheISA::PCState pcState = thread->pcState(); 798733Sgeoffrey.blake@arm.com TheISA::advancePC(pcState, curStaticInst); 808733Sgeoffrey.blake@arm.com thread->pcState(pcState); 818733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Advancing PC to %s.\n", thread->pcState()); 828733Sgeoffrey.blake@arm.com } 838733Sgeoffrey.blake@arm.com } 848733Sgeoffrey.blake@arm.com} 858733Sgeoffrey.blake@arm.com////////////////////////////////////////////////// 868733Sgeoffrey.blake@arm.com 878733Sgeoffrey.blake@arm.comtemplate <class Impl> 888733Sgeoffrey.blake@arm.comvoid 898733Sgeoffrey.blake@arm.comChecker<Impl>::handlePendingInt() 908733Sgeoffrey.blake@arm.com{ 918733Sgeoffrey.blake@arm.com DPRINTF(Checker, "IRQ detected at PC: %s with %d insts in buffer\n", 928733Sgeoffrey.blake@arm.com thread->pcState(), instList.size()); 938733Sgeoffrey.blake@arm.com DynInstPtr boundaryInst = NULL; 948733Sgeoffrey.blake@arm.com if (!instList.empty()) { 958733Sgeoffrey.blake@arm.com // Set the instructions as completed and verify as much as possible. 968733Sgeoffrey.blake@arm.com DynInstPtr inst; 978733Sgeoffrey.blake@arm.com typename std::list<DynInstPtr>::iterator itr; 988733Sgeoffrey.blake@arm.com 998733Sgeoffrey.blake@arm.com for (itr = instList.begin(); itr != instList.end(); itr++) { 1008733Sgeoffrey.blake@arm.com (*itr)->setCompleted(); 1018733Sgeoffrey.blake@arm.com } 1028733Sgeoffrey.blake@arm.com 1038733Sgeoffrey.blake@arm.com inst = instList.front(); 1048733Sgeoffrey.blake@arm.com boundaryInst = instList.back(); 1058733Sgeoffrey.blake@arm.com verify(inst); // verify the instructions 1068733Sgeoffrey.blake@arm.com inst = NULL; 1078733Sgeoffrey.blake@arm.com } 1088733Sgeoffrey.blake@arm.com if ((!boundaryInst && curMacroStaticInst && 1098733Sgeoffrey.blake@arm.com curStaticInst->isDelayedCommit() && 1108733Sgeoffrey.blake@arm.com !curStaticInst->isLastMicroop()) || 1118733Sgeoffrey.blake@arm.com (boundaryInst && boundaryInst->isDelayedCommit() && 1128733Sgeoffrey.blake@arm.com !boundaryInst->isLastMicroop())) { 1138733Sgeoffrey.blake@arm.com panic("%lli: Trying to take an interrupt in middle of " 1148733Sgeoffrey.blake@arm.com "a non-interuptable instruction!", curTick()); 1158733Sgeoffrey.blake@arm.com } 1168733Sgeoffrey.blake@arm.com boundaryInst = NULL; 1178733Sgeoffrey.blake@arm.com predecoder.reset(); 1188733Sgeoffrey.blake@arm.com curMacroStaticInst = StaticInst::nullStaticInstPtr; 1198733Sgeoffrey.blake@arm.com} 1208733Sgeoffrey.blake@arm.com 1218733Sgeoffrey.blake@arm.comtemplate <class Impl> 1228733Sgeoffrey.blake@arm.comvoid 1238733Sgeoffrey.blake@arm.comChecker<Impl>::verify(DynInstPtr &completed_inst) 1242315SN/A{ 1252315SN/A DynInstPtr inst; 1262315SN/A 1278733Sgeoffrey.blake@arm.com // Make sure serializing instructions are actually 1288733Sgeoffrey.blake@arm.com // seen as serializing to commit. instList should be 1298733Sgeoffrey.blake@arm.com // empty in these cases. 1308733Sgeoffrey.blake@arm.com if ((completed_inst->isSerializing() || 1318733Sgeoffrey.blake@arm.com completed_inst->isSerializeBefore()) && 1328733Sgeoffrey.blake@arm.com (!instList.empty() ? 1338733Sgeoffrey.blake@arm.com (instList.front()->seqNum != completed_inst->seqNum) : 0)) { 1348733Sgeoffrey.blake@arm.com panic("%lli: Instruction sn:%lli at PC %s is serializing before but is" 1358733Sgeoffrey.blake@arm.com " entering instList with other instructions\n", curTick(), 1368733Sgeoffrey.blake@arm.com completed_inst->seqNum, completed_inst->pcState()); 1378733Sgeoffrey.blake@arm.com } 1388733Sgeoffrey.blake@arm.com 1392332SN/A // Either check this instruction, or add it to a list of 1402332SN/A // instructions waiting to be checked. Instructions must be 1412332SN/A // checked in program order, so if a store has committed yet not 1422332SN/A // completed, there may be some instructions that are waiting 1432332SN/A // behind it that have completed and must be checked. 1442315SN/A if (!instList.empty()) { 1452315SN/A if (youngestSN < completed_inst->seqNum) { 1468733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Adding instruction [sn:%lli] PC:%s to list\n", 1478733Sgeoffrey.blake@arm.com completed_inst->seqNum, completed_inst->pcState()); 1482315SN/A instList.push_back(completed_inst); 1492315SN/A youngestSN = completed_inst->seqNum; 1502315SN/A } 1512315SN/A 1522315SN/A if (!instList.front()->isCompleted()) { 1532315SN/A return; 1542315SN/A } else { 1552315SN/A inst = instList.front(); 1562315SN/A instList.pop_front(); 1572315SN/A } 1582315SN/A } else { 1592315SN/A if (!completed_inst->isCompleted()) { 1602315SN/A if (youngestSN < completed_inst->seqNum) { 1618733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Adding instruction [sn:%lli] PC:%s to list\n", 1628733Sgeoffrey.blake@arm.com completed_inst->seqNum, completed_inst->pcState()); 1632315SN/A instList.push_back(completed_inst); 1642315SN/A youngestSN = completed_inst->seqNum; 1652315SN/A } 1662315SN/A return; 1672315SN/A } else { 1682315SN/A if (youngestSN < completed_inst->seqNum) { 1692315SN/A inst = completed_inst; 1702315SN/A youngestSN = completed_inst->seqNum; 1712315SN/A } else { 1722315SN/A return; 1732315SN/A } 1742315SN/A } 1752315SN/A } 1762315SN/A 1778733Sgeoffrey.blake@arm.com // Make sure a serializing instruction is actually seen as 1788733Sgeoffrey.blake@arm.com // serializing. instList should be empty here 1798733Sgeoffrey.blake@arm.com if (inst->isSerializeAfter() && !instList.empty()) { 1808733Sgeoffrey.blake@arm.com panic("%lli: Instruction sn:%lli at PC %s is serializing after but is" 1818733Sgeoffrey.blake@arm.com " exiting instList with other instructions\n", curTick(), 1828733Sgeoffrey.blake@arm.com completed_inst->seqNum, completed_inst->pcState()); 1838733Sgeoffrey.blake@arm.com } 1842354SN/A unverifiedInst = inst; 1858733Sgeoffrey.blake@arm.com inst = NULL; 1862354SN/A 1872332SN/A // Try to check all instructions that are completed, ending if we 1882332SN/A // run out of instructions to check or if an instruction is not 1892332SN/A // yet completed. 1902315SN/A while (1) { 1918733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Processing instruction [sn:%lli] PC:%s.\n", 1928733Sgeoffrey.blake@arm.com unverifiedInst->seqNum, unverifiedInst->pcState()); 1938733Sgeoffrey.blake@arm.com unverifiedReq = NULL; 1948733Sgeoffrey.blake@arm.com unverifiedReq = unverifiedInst->reqToVerify; 1958733Sgeoffrey.blake@arm.com unverifiedMemData = unverifiedInst->memData; 1968733Sgeoffrey.blake@arm.com // Make sure results queue is empty 1978733Sgeoffrey.blake@arm.com while (!result.empty()) { 1988733Sgeoffrey.blake@arm.com result.pop(); 1998733Sgeoffrey.blake@arm.com } 2002315SN/A numCycles++; 2012315SN/A 2022315SN/A Fault fault = NoFault; 2032315SN/A 2042315SN/A // maintain $r0 semantics 2052683SN/A thread->setIntReg(ZeroReg, 0); 2062315SN/A#ifdef TARGET_ALPHA 2072683SN/A thread->setFloatRegDouble(ZeroReg, 0.0); 2082315SN/A#endif // TARGET_ALPHA 2092315SN/A 2102332SN/A // Check if any recent PC changes match up with anything we 2112332SN/A // expect to happen. This is mostly to check if traps or 2122332SN/A // PC-based events have occurred in both the checker and CPU. 2132315SN/A if (changedPC) { 2148733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Changed PC recently to %s\n", 2158733Sgeoffrey.blake@arm.com thread->pcState()); 2162315SN/A if (willChangePC) { 2178733Sgeoffrey.blake@arm.com if (newPCState == thread->pcState()) { 2182315SN/A DPRINTF(Checker, "Changed PC matches expected PC\n"); 2192315SN/A } else { 2202332SN/A warn("%lli: Changed PC does not match expected PC, " 2218733Sgeoffrey.blake@arm.com "changed: %s, expected: %s", 2228733Sgeoffrey.blake@arm.com curTick(), thread->pcState(), newPCState); 2232732SN/A CheckerCPU::handleError(); 2242315SN/A } 2252315SN/A willChangePC = false; 2262315SN/A } 2272315SN/A changedPC = false; 2282315SN/A } 2292315SN/A if (changedNextPC) { 2302315SN/A DPRINTF(Checker, "Changed NextPC recently to %#x\n", 2318733Sgeoffrey.blake@arm.com thread->nextInstAddr()); 2322315SN/A changedNextPC = false; 2332315SN/A } 2342315SN/A 2352332SN/A // Try to fetch the instruction 2368733Sgeoffrey.blake@arm.com uint64_t fetchOffset = 0; 2378733Sgeoffrey.blake@arm.com bool fetchDone = false; 2382332SN/A 2398733Sgeoffrey.blake@arm.com while (!fetchDone) { 2408733Sgeoffrey.blake@arm.com Addr fetch_PC = thread->instAddr(); 2418733Sgeoffrey.blake@arm.com fetch_PC = (fetch_PC & PCMask) + fetchOffset; 2422332SN/A 2438733Sgeoffrey.blake@arm.com // If not in the middle of a macro instruction 2448733Sgeoffrey.blake@arm.com if (!curMacroStaticInst) { 2458733Sgeoffrey.blake@arm.com // set up memory request for instruction fetch 2468733Sgeoffrey.blake@arm.com memReq = new Request(unverifiedInst->threadNumber, fetch_PC, 2478733Sgeoffrey.blake@arm.com sizeof(MachInst), 2488733Sgeoffrey.blake@arm.com 0, 2498733Sgeoffrey.blake@arm.com fetch_PC, thread->contextId(), 2508733Sgeoffrey.blake@arm.com unverifiedInst->threadNumber); 2518733Sgeoffrey.blake@arm.com memReq->setVirt(0, fetch_PC, sizeof(MachInst), 2528733Sgeoffrey.blake@arm.com Request::INST_FETCH, thread->instAddr()); 2532679SN/A 2542315SN/A 2558733Sgeoffrey.blake@arm.com fault = itb->translateFunctional(memReq, tc, BaseTLB::Execute); 2562315SN/A 2578733Sgeoffrey.blake@arm.com if (fault != NoFault) { 2588733Sgeoffrey.blake@arm.com if (unverifiedInst->getFault() == NoFault) { 2598733Sgeoffrey.blake@arm.com // In this case the instruction was not a dummy 2608733Sgeoffrey.blake@arm.com // instruction carrying an ITB fault. In the single 2618733Sgeoffrey.blake@arm.com // threaded case the ITB should still be able to 2628733Sgeoffrey.blake@arm.com // translate this instruction; in the SMT case it's 2638733Sgeoffrey.blake@arm.com // possible that its ITB entry was kicked out. 2648733Sgeoffrey.blake@arm.com warn("%lli: Instruction PC %s was not found in the " 2658733Sgeoffrey.blake@arm.com "ITB!", curTick(), thread->pcState()); 2668733Sgeoffrey.blake@arm.com handleError(unverifiedInst); 2672315SN/A 2688733Sgeoffrey.blake@arm.com // go to the next instruction 2698733Sgeoffrey.blake@arm.com advancePC(NoFault); 2702315SN/A 2718733Sgeoffrey.blake@arm.com // Give up on an ITB fault.. 2728733Sgeoffrey.blake@arm.com delete memReq; 2738733Sgeoffrey.blake@arm.com unverifiedInst = NULL; 2748733Sgeoffrey.blake@arm.com return; 2758733Sgeoffrey.blake@arm.com } else { 2768733Sgeoffrey.blake@arm.com // The instruction is carrying an ITB fault. Handle 2778733Sgeoffrey.blake@arm.com // the fault and see if our results match the CPU on 2788733Sgeoffrey.blake@arm.com // the next tick(). 2798733Sgeoffrey.blake@arm.com fault = unverifiedInst->getFault(); 2808733Sgeoffrey.blake@arm.com delete memReq; 2818733Sgeoffrey.blake@arm.com break; 2828733Sgeoffrey.blake@arm.com } 2838733Sgeoffrey.blake@arm.com } else { 2848733Sgeoffrey.blake@arm.com PacketPtr pkt = new Packet(memReq, 2858733Sgeoffrey.blake@arm.com MemCmd::ReadReq, 2868733Sgeoffrey.blake@arm.com Packet::Broadcast); 2878733Sgeoffrey.blake@arm.com 2888733Sgeoffrey.blake@arm.com pkt->dataStatic(&machInst); 2898733Sgeoffrey.blake@arm.com icachePort->sendFunctional(pkt); 2908733Sgeoffrey.blake@arm.com machInst = gtoh(machInst); 2918733Sgeoffrey.blake@arm.com 2928733Sgeoffrey.blake@arm.com delete memReq; 2938733Sgeoffrey.blake@arm.com delete pkt; 2948733Sgeoffrey.blake@arm.com } 2958733Sgeoffrey.blake@arm.com } 2968733Sgeoffrey.blake@arm.com 2978733Sgeoffrey.blake@arm.com if (fault == NoFault) { 2988733Sgeoffrey.blake@arm.com TheISA::PCState pcState = thread->pcState(); 2998733Sgeoffrey.blake@arm.com 3008733Sgeoffrey.blake@arm.com if (isRomMicroPC(pcState.microPC())) { 3018733Sgeoffrey.blake@arm.com fetchDone = true; 3028733Sgeoffrey.blake@arm.com curStaticInst = 3038733Sgeoffrey.blake@arm.com microcodeRom.fetchMicroop(pcState.microPC(), NULL); 3048733Sgeoffrey.blake@arm.com } else if (!curMacroStaticInst) { 3058733Sgeoffrey.blake@arm.com //We're not in the middle of a macro instruction 3068733Sgeoffrey.blake@arm.com StaticInstPtr instPtr = NULL; 3078733Sgeoffrey.blake@arm.com 3088733Sgeoffrey.blake@arm.com //Predecode, ie bundle up an ExtMachInst 3098733Sgeoffrey.blake@arm.com predecoder.setTC(thread->getTC()); 3108733Sgeoffrey.blake@arm.com //If more fetch data is needed, pass it in. 3118733Sgeoffrey.blake@arm.com Addr fetchPC = (pcState.instAddr() & PCMask) + fetchOffset; 3128733Sgeoffrey.blake@arm.com predecoder.moreBytes(pcState, fetchPC, machInst); 3138733Sgeoffrey.blake@arm.com 3148733Sgeoffrey.blake@arm.com //If an instruction is ready, decode it. 3158733Sgeoffrey.blake@arm.com //Otherwise, we'll have to fetch beyond the 3168733Sgeoffrey.blake@arm.com //MachInst at the current pc. 3178733Sgeoffrey.blake@arm.com if (predecoder.extMachInstReady()) { 3188733Sgeoffrey.blake@arm.com fetchDone = true; 3198733Sgeoffrey.blake@arm.com ExtMachInst newMachInst = 3208733Sgeoffrey.blake@arm.com predecoder.getExtMachInst(pcState); 3218733Sgeoffrey.blake@arm.com thread->pcState(pcState); 3228733Sgeoffrey.blake@arm.com instPtr = thread->decoder.decode(newMachInst, 3238733Sgeoffrey.blake@arm.com pcState.instAddr()); 3248733Sgeoffrey.blake@arm.com machInst = newMachInst; 3258733Sgeoffrey.blake@arm.com } else { 3268733Sgeoffrey.blake@arm.com fetchDone = false; 3278733Sgeoffrey.blake@arm.com fetchOffset += sizeof(TheISA::MachInst); 3288733Sgeoffrey.blake@arm.com } 3298733Sgeoffrey.blake@arm.com 3308733Sgeoffrey.blake@arm.com //If we decoded an instruction and it's microcoded, 3318733Sgeoffrey.blake@arm.com //start pulling out micro ops 3328733Sgeoffrey.blake@arm.com if (instPtr && instPtr->isMacroop()) { 3338733Sgeoffrey.blake@arm.com curMacroStaticInst = instPtr; 3348733Sgeoffrey.blake@arm.com curStaticInst = 3358733Sgeoffrey.blake@arm.com instPtr->fetchMicroop(pcState.microPC()); 3368733Sgeoffrey.blake@arm.com } else { 3378733Sgeoffrey.blake@arm.com curStaticInst = instPtr; 3388733Sgeoffrey.blake@arm.com } 3398733Sgeoffrey.blake@arm.com } else { 3408733Sgeoffrey.blake@arm.com // Read the next micro op from the macro-op 3418733Sgeoffrey.blake@arm.com curStaticInst = 3428733Sgeoffrey.blake@arm.com curMacroStaticInst->fetchMicroop(pcState.microPC()); 3438733Sgeoffrey.blake@arm.com fetchDone = true; 3448733Sgeoffrey.blake@arm.com } 3452323SN/A } 3462315SN/A } 3478733Sgeoffrey.blake@arm.com // reset predecoder on Checker 3488733Sgeoffrey.blake@arm.com predecoder.reset(); 3492315SN/A 3508733Sgeoffrey.blake@arm.com // Check Checker and CPU get same instruction, and record 3518733Sgeoffrey.blake@arm.com // any faults the CPU may have had. 3528733Sgeoffrey.blake@arm.com Fault unverifiedFault; 3532323SN/A if (fault == NoFault) { 3548733Sgeoffrey.blake@arm.com unverifiedFault = unverifiedInst->getFault(); 3552679SN/A 3562323SN/A // Checks that the instruction matches what we expected it to be. 3572323SN/A // Checks both the machine instruction and the PC. 3588733Sgeoffrey.blake@arm.com validateInst(unverifiedInst); 3592323SN/A } 3602315SN/A 3618733Sgeoffrey.blake@arm.com // keep an instruction count 3628733Sgeoffrey.blake@arm.com numInst++; 3638733Sgeoffrey.blake@arm.com 3642679SN/A 3652315SN/A // Either the instruction was a fault and we should process the fault, 3662315SN/A // or we should just go ahead execute the instruction. This assumes 3672315SN/A // that the instruction is properly marked as a fault. 3682315SN/A if (fault == NoFault) { 3698733Sgeoffrey.blake@arm.com // Execute Checker instruction and trace 3708733Sgeoffrey.blake@arm.com if (!unverifiedInst->isUnverifiable()) { 3718733Sgeoffrey.blake@arm.com Trace::InstRecord *traceData = tracer->getInstRecord(curTick(), 3728733Sgeoffrey.blake@arm.com tc, 3738733Sgeoffrey.blake@arm.com curStaticInst, 3748733Sgeoffrey.blake@arm.com pcState(), 3758733Sgeoffrey.blake@arm.com curMacroStaticInst); 3768733Sgeoffrey.blake@arm.com fault = curStaticInst->execute(this, traceData); 3778733Sgeoffrey.blake@arm.com if (traceData) { 3788733Sgeoffrey.blake@arm.com traceData->dump(); 3798733Sgeoffrey.blake@arm.com delete traceData; 3808733Sgeoffrey.blake@arm.com } 3818733Sgeoffrey.blake@arm.com } 3822315SN/A 3838733Sgeoffrey.blake@arm.com if (fault == NoFault && unverifiedFault == NoFault) { 3848733Sgeoffrey.blake@arm.com thread->funcExeInst++; 3858733Sgeoffrey.blake@arm.com // Checks to make sure instrution results are correct. 3868733Sgeoffrey.blake@arm.com validateExecution(unverifiedInst); 3872315SN/A 3888733Sgeoffrey.blake@arm.com if (curStaticInst->isLoad()) { 3898733Sgeoffrey.blake@arm.com ++numLoad; 3908733Sgeoffrey.blake@arm.com } 3918733Sgeoffrey.blake@arm.com } else if (fault != NoFault && unverifiedFault == NoFault) { 3928733Sgeoffrey.blake@arm.com panic("%lli: sn: %lli at PC: %s took a fault in checker " 3938733Sgeoffrey.blake@arm.com "but not in driver CPU\n", curTick(), 3948733Sgeoffrey.blake@arm.com unverifiedInst->seqNum, unverifiedInst->pcState()); 3958733Sgeoffrey.blake@arm.com } else if (fault == NoFault && unverifiedFault != NoFault) { 3968733Sgeoffrey.blake@arm.com panic("%lli: sn: %lli at PC: %s took a fault in driver " 3978733Sgeoffrey.blake@arm.com "CPU but not in checker\n", curTick(), 3988733Sgeoffrey.blake@arm.com unverifiedInst->seqNum, unverifiedInst->pcState()); 3992315SN/A } 4002315SN/A } 4012315SN/A 4028733Sgeoffrey.blake@arm.com // Take any faults here 4032315SN/A if (fault != NoFault) { 4042315SN/A#if FULL_SYSTEM 4057678Sgblack@eecs.umich.edu fault->invoke(tc, curStaticInst); 4062315SN/A willChangePC = true; 4078733Sgeoffrey.blake@arm.com newPCState = thread->pcState(); 4088733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Fault, PC is now %s\n", newPCState); 4098733Sgeoffrey.blake@arm.com curMacroStaticInst = StaticInst::nullStaticInstPtr; 4102838Sktlim@umich.edu#endif 4112315SN/A } else { 4128733Sgeoffrey.blake@arm.com advancePC(fault); 4132315SN/A } 4142315SN/A 4152315SN/A#if FULL_SYSTEM 4162332SN/A // @todo: Determine if these should happen only if the 4172332SN/A // instruction hasn't faulted. In the SimpleCPU case this may 4182332SN/A // not be true, but in the O3 or Ozone case this may be true. 4192315SN/A Addr oldpc; 4202315SN/A int count = 0; 4212315SN/A do { 4228733Sgeoffrey.blake@arm.com oldpc = thread->instAddr(); 4232690SN/A system->pcEventQueue.service(tc); 4242315SN/A count++; 4258733Sgeoffrey.blake@arm.com } while (oldpc != thread->instAddr()); 4262315SN/A if (count > 1) { 4272315SN/A willChangePC = true; 4288733Sgeoffrey.blake@arm.com newPCState = thread->pcState(); 4298733Sgeoffrey.blake@arm.com DPRINTF(Checker, "PC Event, PC is now %s\n", newPCState); 4302315SN/A } 4312315SN/A#endif 4322315SN/A 4332332SN/A // @todo: Optionally can check all registers. (Or just those 4342315SN/A // that have been modified). 4352315SN/A validateState(); 4362315SN/A 4372332SN/A // Continue verifying instructions if there's another completed 4382332SN/A // instruction waiting to be verified. 4392315SN/A if (instList.empty()) { 4402315SN/A break; 4412315SN/A } else if (instList.front()->isCompleted()) { 4428733Sgeoffrey.blake@arm.com unverifiedInst = NULL; 4438733Sgeoffrey.blake@arm.com unverifiedInst = instList.front(); 4442315SN/A instList.pop_front(); 4452315SN/A } else { 4462315SN/A break; 4472315SN/A } 4482315SN/A } 4492354SN/A unverifiedInst = NULL; 4502315SN/A} 4512315SN/A 4528733Sgeoffrey.blake@arm.comtemplate <class Impl> 4532315SN/Avoid 4548733Sgeoffrey.blake@arm.comChecker<Impl>::switchOut() 4552315SN/A{ 4562315SN/A instList.clear(); 4572315SN/A} 4582315SN/A 4598733Sgeoffrey.blake@arm.comtemplate <class Impl> 4602315SN/Avoid 4618733Sgeoffrey.blake@arm.comChecker<Impl>::takeOverFrom(BaseCPU *oldCPU) 4622315SN/A{ 4632315SN/A} 4642315SN/A 4658733Sgeoffrey.blake@arm.comtemplate <class Impl> 4662315SN/Avoid 4678733Sgeoffrey.blake@arm.comChecker<Impl>::validateInst(DynInstPtr &inst) 4682315SN/A{ 4698733Sgeoffrey.blake@arm.com if (inst->instAddr() != thread->instAddr()) { 4708733Sgeoffrey.blake@arm.com warn("%lli: PCs do not match! Inst: %s, checker: %s", 4718733Sgeoffrey.blake@arm.com curTick(), inst->pcState(), thread->pcState()); 4722315SN/A if (changedPC) { 4732332SN/A warn("%lli: Changed PCs recently, may not be an error", 4747823Ssteve.reinhardt@amd.com curTick()); 4752315SN/A } else { 4762732SN/A handleError(inst); 4772315SN/A } 4782315SN/A } 4792315SN/A 4802332SN/A MachInst mi = static_cast<MachInst>(inst->staticInst->machInst); 4812332SN/A 4822332SN/A if (mi != machInst) { 4838733Sgeoffrey.blake@arm.com panic("%lli: Binary instructions do not match! Inst: %#x, " 4842332SN/A "checker: %#x", 4857823Ssteve.reinhardt@amd.com curTick(), mi, machInst); 4862732SN/A handleError(inst); 4872315SN/A } 4882315SN/A} 4892315SN/A 4908733Sgeoffrey.blake@arm.comtemplate <class Impl> 4912315SN/Avoid 4928733Sgeoffrey.blake@arm.comChecker<Impl>::validateExecution(DynInstPtr &inst) 4932315SN/A{ 4948733Sgeoffrey.blake@arm.com uint64_t checker_val; 4958733Sgeoffrey.blake@arm.com uint64_t inst_val; 4968733Sgeoffrey.blake@arm.com int idx = -1; 4972732SN/A bool result_mismatch = false; 4988733Sgeoffrey.blake@arm.com 4998733Sgeoffrey.blake@arm.com if (inst->isUnverifiable()) { 5008733Sgeoffrey.blake@arm.com // Unverifiable instructions assume they were executed 5018733Sgeoffrey.blake@arm.com // properly by the CPU. Grab the result from the 5028733Sgeoffrey.blake@arm.com // instruction and write it to the register. 5038733Sgeoffrey.blake@arm.com copyResult(inst, 0, idx); 5048733Sgeoffrey.blake@arm.com } else if (inst->numDestRegs() > 0 && !result.empty()) { 5058733Sgeoffrey.blake@arm.com DPRINTF(Checker, "Dest regs %d, number of checker dest regs %d\n", 5068733Sgeoffrey.blake@arm.com inst->numDestRegs(), result.size()); 5078733Sgeoffrey.blake@arm.com for (int i = 0; i < inst->numDestRegs() && !result.empty(); i++) { 5088733Sgeoffrey.blake@arm.com result.front().get(checker_val); 5098733Sgeoffrey.blake@arm.com result.pop(); 5108733Sgeoffrey.blake@arm.com inst_val = 0; 5118733Sgeoffrey.blake@arm.com inst->template popResult<uint64_t>(inst_val); 5128733Sgeoffrey.blake@arm.com if (checker_val != inst_val) { 5138733Sgeoffrey.blake@arm.com result_mismatch = true; 5148733Sgeoffrey.blake@arm.com idx = i; 5158733Sgeoffrey.blake@arm.com break; 5168733Sgeoffrey.blake@arm.com } 5172732SN/A } 5188733Sgeoffrey.blake@arm.com } // Checker CPU checks all the saved results in the dyninst passed by 5198733Sgeoffrey.blake@arm.com // the cpu model being checked against the saved results present in 5208733Sgeoffrey.blake@arm.com // the static inst executed in the Checker. Sometimes the number 5218733Sgeoffrey.blake@arm.com // of saved results differs between the dyninst and static inst, but 5228733Sgeoffrey.blake@arm.com // this is ok and not a bug. May be worthwhile to try and correct this. 5232732SN/A 5242732SN/A if (result_mismatch) { 5252732SN/A warn("%lli: Instruction results do not match! (Values may not " 5262732SN/A "actually be integers) Inst: %#x, checker: %#x", 5278733Sgeoffrey.blake@arm.com curTick(), inst_val, checker_val); 5282732SN/A 5292732SN/A // It's useful to verify load values from memory, but in MP 5302732SN/A // systems the value obtained at execute may be different than 5312732SN/A // the value obtained at completion. Similarly DMA can 5322732SN/A // present the same problem on even UP systems. Thus there is 5332732SN/A // the option to only warn on loads having a result error. 5348733Sgeoffrey.blake@arm.com // The load/store queue in Detailed CPU can also cause problems 5358733Sgeoffrey.blake@arm.com // if load/store forwarding is allowed. 5362732SN/A if (inst->isLoad() && warnOnlyOnLoadError) { 5378733Sgeoffrey.blake@arm.com copyResult(inst, inst_val, idx); 5382732SN/A } else { 5392732SN/A handleError(inst); 5402315SN/A } 5412315SN/A } 5422315SN/A 5438733Sgeoffrey.blake@arm.com if (inst->nextInstAddr() != thread->nextInstAddr()) { 5442332SN/A warn("%lli: Instruction next PCs do not match! Inst: %#x, " 5452332SN/A "checker: %#x", 5468733Sgeoffrey.blake@arm.com curTick(), inst->nextInstAddr(), thread->nextInstAddr()); 5472732SN/A handleError(inst); 5482315SN/A } 5492315SN/A 5502315SN/A // Checking side effect registers can be difficult if they are not 5512315SN/A // checked simultaneously with the execution of the instruction. 5522315SN/A // This is because other valid instructions may have modified 5532315SN/A // these registers in the meantime, and their values are not 5542315SN/A // stored within the DynInst. 5552315SN/A while (!miscRegIdxs.empty()) { 5562315SN/A int misc_reg_idx = miscRegIdxs.front(); 5572315SN/A miscRegIdxs.pop(); 5582315SN/A 5594172Ssaidi@eecs.umich.edu if (inst->tcBase()->readMiscRegNoEffect(misc_reg_idx) != 5604172Ssaidi@eecs.umich.edu thread->readMiscRegNoEffect(misc_reg_idx)) { 5612332SN/A warn("%lli: Misc reg idx %i (side effect) does not match! " 5622332SN/A "Inst: %#x, checker: %#x", 5637823Ssteve.reinhardt@amd.com curTick(), misc_reg_idx, 5644172Ssaidi@eecs.umich.edu inst->tcBase()->readMiscRegNoEffect(misc_reg_idx), 5654172Ssaidi@eecs.umich.edu thread->readMiscRegNoEffect(misc_reg_idx)); 5662732SN/A handleError(inst); 5672315SN/A } 5682315SN/A } 5692315SN/A} 5702315SN/A 5718733Sgeoffrey.blake@arm.com 5728733Sgeoffrey.blake@arm.com// This function is weird, if it is called it means the Checker and 5738733Sgeoffrey.blake@arm.com// O3 have diverged, so panic is called for now. It may be useful 5748733Sgeoffrey.blake@arm.com// to resynch states and continue if the divergence is a false positive 5758733Sgeoffrey.blake@arm.comtemplate <class Impl> 5762315SN/Avoid 5778733Sgeoffrey.blake@arm.comChecker<Impl>::validateState() 5782315SN/A{ 5792354SN/A if (updateThisCycle) { 5808733Sgeoffrey.blake@arm.com // Change this back to warn if divergences end up being false positives 5818733Sgeoffrey.blake@arm.com panic("%lli: Instruction PC %#x results didn't match up, copying all " 5828733Sgeoffrey.blake@arm.com "registers from main CPU", curTick(), unverifiedInst->instAddr()); 5838733Sgeoffrey.blake@arm.com 5848733Sgeoffrey.blake@arm.com // Terribly convoluted way to make sure O3 model does not implode 5858733Sgeoffrey.blake@arm.com bool inSyscall = unverifiedInst->thread->inSyscall; 5868733Sgeoffrey.blake@arm.com unverifiedInst->thread->inSyscall = true; 5878733Sgeoffrey.blake@arm.com 5882354SN/A // Heavy-weight copying of all registers 5893126Sktlim@umich.edu thread->copyArchRegs(unverifiedInst->tcBase()); 5908733Sgeoffrey.blake@arm.com unverifiedInst->thread->inSyscall = inSyscall; 5918733Sgeoffrey.blake@arm.com 5928733Sgeoffrey.blake@arm.com // Set curStaticInst to unverifiedInst->staticInst 5938733Sgeoffrey.blake@arm.com curStaticInst = unverifiedInst->staticInst; 5942356SN/A // Also advance the PC. Hopefully no PC-based events happened. 5958733Sgeoffrey.blake@arm.com advancePC(NoFault); 5962354SN/A updateThisCycle = false; 5973126Sktlim@umich.edu } 5982315SN/A} 5992315SN/A 6008733Sgeoffrey.blake@arm.comtemplate <class Impl> 6012315SN/Avoid 6028733Sgeoffrey.blake@arm.comChecker<Impl>::copyResult(DynInstPtr &inst, uint64_t mismatch_val, 6038733Sgeoffrey.blake@arm.com int start_idx) 6042732SN/A{ 6058733Sgeoffrey.blake@arm.com // We've already popped one dest off the queue, 6068733Sgeoffrey.blake@arm.com // so do the fix-up then start with the next dest reg; 6078733Sgeoffrey.blake@arm.com if (start_idx >= 0) { 6088733Sgeoffrey.blake@arm.com RegIndex idx = inst->destRegIdx(start_idx); 6098733Sgeoffrey.blake@arm.com if (idx < TheISA::FP_Base_DepTag) { 6108733Sgeoffrey.blake@arm.com thread->setIntReg(idx, mismatch_val); 6118733Sgeoffrey.blake@arm.com } else if (idx < TheISA::Ctrl_Base_DepTag) { 6128733Sgeoffrey.blake@arm.com thread->setFloatRegBits(idx, mismatch_val); 6138733Sgeoffrey.blake@arm.com } else if (idx < TheISA::Max_DepTag) { 6148733Sgeoffrey.blake@arm.com thread->setMiscReg(idx - TheISA::Ctrl_Base_DepTag, 6158733Sgeoffrey.blake@arm.com mismatch_val); 6168733Sgeoffrey.blake@arm.com } 6178733Sgeoffrey.blake@arm.com } 6188733Sgeoffrey.blake@arm.com start_idx++; 6198733Sgeoffrey.blake@arm.com uint64_t res = 0; 6208733Sgeoffrey.blake@arm.com for (int i = start_idx; i < inst->numDestRegs(); i++) { 6218733Sgeoffrey.blake@arm.com RegIndex idx = inst->destRegIdx(i); 6228733Sgeoffrey.blake@arm.com inst->template popResult<uint64_t>(res); 6238733Sgeoffrey.blake@arm.com if (idx < TheISA::FP_Base_DepTag) { 6248733Sgeoffrey.blake@arm.com thread->setIntReg(idx, res); 6258733Sgeoffrey.blake@arm.com } else if (idx < TheISA::Ctrl_Base_DepTag) { 6268733Sgeoffrey.blake@arm.com thread->setFloatRegBits(idx, res); 6278733Sgeoffrey.blake@arm.com } else if (idx < TheISA::Max_DepTag) { 6288733Sgeoffrey.blake@arm.com // Try to get the proper misc register index for ARM here... 6298733Sgeoffrey.blake@arm.com thread->setMiscReg(idx - TheISA::Ctrl_Base_DepTag, res); 6308733Sgeoffrey.blake@arm.com } // else Register is out of range... 6312732SN/A } 6322732SN/A} 6332732SN/A 6348733Sgeoffrey.blake@arm.comtemplate <class Impl> 6352732SN/Avoid 6368733Sgeoffrey.blake@arm.comChecker<Impl>::dumpAndExit(DynInstPtr &inst) 6372732SN/A{ 6382732SN/A cprintf("Error detected, instruction information:\n"); 6398733Sgeoffrey.blake@arm.com cprintf("PC:%s, nextPC:%#x\n[sn:%lli]\n[tid:%i]\n" 6402732SN/A "Completed:%i\n", 6418733Sgeoffrey.blake@arm.com inst->pcState(), 6428733Sgeoffrey.blake@arm.com inst->nextInstAddr(), 6432732SN/A inst->seqNum, 6442732SN/A inst->threadNumber, 6452732SN/A inst->isCompleted()); 6462732SN/A inst->dump(); 6472732SN/A CheckerCPU::dumpAndExit(); 6482732SN/A} 6492732SN/A 6508733Sgeoffrey.blake@arm.comtemplate <class Impl> 6512732SN/Avoid 6528733Sgeoffrey.blake@arm.comChecker<Impl>::dumpInsts() 6532315SN/A{ 6542315SN/A int num = 0; 6552315SN/A 6562315SN/A InstListIt inst_list_it = --(instList.end()); 6572315SN/A 6582315SN/A cprintf("Inst list size: %i\n", instList.size()); 6592315SN/A 6602315SN/A while (inst_list_it != instList.end()) 6612315SN/A { 6622315SN/A cprintf("Instruction:%i\n", 6632315SN/A num); 6642315SN/A 6658733Sgeoffrey.blake@arm.com cprintf("PC:%s\n[sn:%lli]\n[tid:%i]\n" 6662315SN/A "Completed:%i\n", 6678733Sgeoffrey.blake@arm.com (*inst_list_it)->pcState(), 6682315SN/A (*inst_list_it)->seqNum, 6692315SN/A (*inst_list_it)->threadNumber, 6702315SN/A (*inst_list_it)->isCompleted()); 6712315SN/A 6722315SN/A cprintf("\n"); 6732315SN/A 6742315SN/A inst_list_it--; 6752315SN/A ++num; 6762315SN/A } 6772315SN/A 6782315SN/A} 679