thread_context.hh revision 2690
12330SN/A/* 22330SN/A * Copyright (c) 2006 The Regents of The University of Michigan 32330SN/A * All rights reserved. 42330SN/A * 52330SN/A * Redistribution and use in source and binary forms, with or without 62330SN/A * modification, are permitted provided that the following conditions are 72330SN/A * met: redistributions of source code must retain the above copyright 82330SN/A * notice, this list of conditions and the following disclaimer; 92330SN/A * redistributions in binary form must reproduce the above copyright 102330SN/A * notice, this list of conditions and the following disclaimer in the 112330SN/A * documentation and/or other materials provided with the distribution; 122330SN/A * neither the name of the copyright holders nor the names of its 132330SN/A * contributors may be used to endorse or promote products derived from 142330SN/A * this software without specific prior written permission. 152330SN/A * 162330SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172330SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182330SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192330SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202330SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212330SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222330SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232330SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242330SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252330SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262330SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Kevin Lim 292330SN/A */ 302330SN/A 312683Sktlim@umich.edu#ifndef __CPU_CHECKER_THREAD_CONTEXT_HH__ 322683Sktlim@umich.edu#define __CPU_CHECKER_THREAD_CONTEXT_HH__ 332315SN/A 342315SN/A#include "cpu/checker/cpu.hh" 352683Sktlim@umich.edu#include "cpu/simple_thread.hh" 362680SN/A#include "cpu/thread_context.hh" 372315SN/A 382315SN/Aclass EndQuiesceEvent; 392330SN/Anamespace Kernel { 402330SN/A class Statistics; 412330SN/A}; 422315SN/A 432350SN/A/** 442680SN/A * Derived ThreadContext class for use with the Checker. The template 452680SN/A * parameter is the ThreadContext class used by the specific CPU being 462683Sktlim@umich.edu * verified. This CheckerThreadContext is then used by the main CPU 472683Sktlim@umich.edu * in place of its usual ThreadContext class. It handles updating the 482683Sktlim@umich.edu * checker's state any time state is updated externally through the 492683Sktlim@umich.edu * ThreadContext. 502350SN/A */ 512680SN/Atemplate <class TC> 522680SN/Aclass CheckerThreadContext : public ThreadContext 532315SN/A{ 542315SN/A public: 552680SN/A CheckerThreadContext(TC *actual_tc, 562683Sktlim@umich.edu CheckerCPU *checker_cpu) 572683Sktlim@umich.edu : actualTC(actual_tc), checkerTC(checker_cpu->thread), 582330SN/A checkerCPU(checker_cpu) 592315SN/A { } 602315SN/A 612315SN/A private: 622683Sktlim@umich.edu /** The main CPU's ThreadContext, or class that implements the 632683Sktlim@umich.edu * ThreadContext interface. */ 642680SN/A TC *actualTC; 652683Sktlim@umich.edu /** The checker's own SimpleThread. Will be updated any time 662683Sktlim@umich.edu * anything uses this ThreadContext to externally update a 672683Sktlim@umich.edu * thread's state. */ 682683Sktlim@umich.edu SimpleThread *checkerTC; 692683Sktlim@umich.edu /** Pointer to the checker CPU. */ 702315SN/A CheckerCPU *checkerCPU; 712315SN/A 722315SN/A public: 732315SN/A 742680SN/A BaseCPU *getCpuPtr() { return actualTC->getCpuPtr(); } 752315SN/A 762315SN/A void setCpuId(int id) 772315SN/A { 782680SN/A actualTC->setCpuId(id); 792680SN/A checkerTC->setCpuId(id); 802315SN/A } 812315SN/A 822680SN/A int readCpuId() { return actualTC->readCpuId(); } 832315SN/A 842315SN/A#if FULL_SYSTEM 852680SN/A System *getSystemPtr() { return actualTC->getSystemPtr(); } 862315SN/A 872680SN/A PhysicalMemory *getPhysMemPtr() { return actualTC->getPhysMemPtr(); } 882315SN/A 892680SN/A AlphaITB *getITBPtr() { return actualTC->getITBPtr(); } 902315SN/A 912680SN/A AlphaDTB *getDTBPtr() { return actualTC->getDTBPtr(); } 922330SN/A 932680SN/A Kernel::Statistics *getKernelStats() { return actualTC->getKernelStats(); } 942690Sktlim@umich.edu 952690Sktlim@umich.edu FunctionalPort *getPhysPort() { return actualTC->getPhysPort(); } 962690Sktlim@umich.edu 972690Sktlim@umich.edu VirtualPort *getVirtPort(ThreadContext *tc = NULL) 982690Sktlim@umich.edu { return actualTC->getVirtPort(); } 992690Sktlim@umich.edu 1002690Sktlim@umich.edu void delVirtPort(VirtualPort *vp) { actualTC->delVirtPort(vp); } 1012315SN/A#else 1022690Sktlim@umich.edu TranslatingPort *getMemPort() { return actualTC->getMemPort(); } 1032690Sktlim@umich.edu 1042680SN/A Process *getProcessPtr() { return actualTC->getProcessPtr(); } 1052315SN/A#endif 1062315SN/A 1072680SN/A Status status() const { return actualTC->status(); } 1082315SN/A 1092315SN/A void setStatus(Status new_status) 1102330SN/A { 1112680SN/A actualTC->setStatus(new_status); 1122680SN/A checkerTC->setStatus(new_status); 1132330SN/A } 1142315SN/A 1152315SN/A /// Set the status to Active. Optional delay indicates number of 1162315SN/A /// cycles to wait before beginning execution. 1172680SN/A void activate(int delay = 1) { actualTC->activate(delay); } 1182315SN/A 1192315SN/A /// Set the status to Suspended. 1202680SN/A void suspend() { actualTC->suspend(); } 1212315SN/A 1222315SN/A /// Set the status to Unallocated. 1232680SN/A void deallocate() { actualTC->deallocate(); } 1242315SN/A 1252315SN/A /// Set the status to Halted. 1262680SN/A void halt() { actualTC->halt(); } 1272315SN/A 1282315SN/A#if FULL_SYSTEM 1292680SN/A void dumpFuncProfile() { actualTC->dumpFuncProfile(); } 1302315SN/A#endif 1312315SN/A 1322680SN/A void takeOverFrom(ThreadContext *oldContext) 1332315SN/A { 1342680SN/A actualTC->takeOverFrom(oldContext); 1352680SN/A checkerTC->takeOverFrom(oldContext); 1362315SN/A } 1372315SN/A 1382680SN/A void regStats(const std::string &name) { actualTC->regStats(name); } 1392315SN/A 1402680SN/A void serialize(std::ostream &os) { actualTC->serialize(os); } 1412315SN/A void unserialize(Checkpoint *cp, const std::string §ion) 1422680SN/A { actualTC->unserialize(cp, section); } 1432315SN/A 1442315SN/A#if FULL_SYSTEM 1452680SN/A EndQuiesceEvent *getQuiesceEvent() { return actualTC->getQuiesceEvent(); } 1462315SN/A 1472680SN/A Tick readLastActivate() { return actualTC->readLastActivate(); } 1482680SN/A Tick readLastSuspend() { return actualTC->readLastSuspend(); } 1492315SN/A 1502680SN/A void profileClear() { return actualTC->profileClear(); } 1512680SN/A void profileSample() { return actualTC->profileSample(); } 1522315SN/A#endif 1532315SN/A 1542680SN/A int getThreadNum() { return actualTC->getThreadNum(); } 1552315SN/A 1562315SN/A // @todo: Do I need this? 1572680SN/A MachInst getInst() { return actualTC->getInst(); } 1582315SN/A 1592315SN/A // @todo: Do I need this? 1602680SN/A void copyArchRegs(ThreadContext *tc) 1612315SN/A { 1622680SN/A actualTC->copyArchRegs(tc); 1632680SN/A checkerTC->copyArchRegs(tc); 1642315SN/A } 1652315SN/A 1662315SN/A void clearArchRegs() 1672315SN/A { 1682680SN/A actualTC->clearArchRegs(); 1692680SN/A checkerTC->clearArchRegs(); 1702315SN/A } 1712315SN/A 1722315SN/A // 1732315SN/A // New accessors for new decoder. 1742315SN/A // 1752315SN/A uint64_t readIntReg(int reg_idx) 1762680SN/A { return actualTC->readIntReg(reg_idx); } 1772315SN/A 1782669SN/A FloatReg readFloatReg(int reg_idx, int width) 1792680SN/A { return actualTC->readFloatReg(reg_idx, width); } 1802315SN/A 1812669SN/A FloatReg readFloatReg(int reg_idx) 1822680SN/A { return actualTC->readFloatReg(reg_idx); } 1832315SN/A 1842669SN/A FloatRegBits readFloatRegBits(int reg_idx, int width) 1852680SN/A { return actualTC->readFloatRegBits(reg_idx, width); } 1862669SN/A 1872669SN/A FloatRegBits readFloatRegBits(int reg_idx) 1882680SN/A { return actualTC->readFloatRegBits(reg_idx); } 1892315SN/A 1902315SN/A void setIntReg(int reg_idx, uint64_t val) 1912315SN/A { 1922680SN/A actualTC->setIntReg(reg_idx, val); 1932680SN/A checkerTC->setIntReg(reg_idx, val); 1942315SN/A } 1952315SN/A 1962669SN/A void setFloatReg(int reg_idx, FloatReg val, int width) 1972315SN/A { 1982680SN/A actualTC->setFloatReg(reg_idx, val, width); 1992680SN/A checkerTC->setFloatReg(reg_idx, val, width); 2002315SN/A } 2012315SN/A 2022669SN/A void setFloatReg(int reg_idx, FloatReg val) 2032315SN/A { 2042680SN/A actualTC->setFloatReg(reg_idx, val); 2052680SN/A checkerTC->setFloatReg(reg_idx, val); 2062315SN/A } 2072315SN/A 2082669SN/A void setFloatRegBits(int reg_idx, FloatRegBits val, int width) 2092315SN/A { 2102680SN/A actualTC->setFloatRegBits(reg_idx, val, width); 2112680SN/A checkerTC->setFloatRegBits(reg_idx, val, width); 2122669SN/A } 2132669SN/A 2142669SN/A void setFloatRegBits(int reg_idx, FloatRegBits val) 2152669SN/A { 2162680SN/A actualTC->setFloatRegBits(reg_idx, val); 2172680SN/A checkerTC->setFloatRegBits(reg_idx, val); 2182315SN/A } 2192315SN/A 2202680SN/A uint64_t readPC() { return actualTC->readPC(); } 2212315SN/A 2222315SN/A void setPC(uint64_t val) 2232315SN/A { 2242680SN/A actualTC->setPC(val); 2252680SN/A checkerTC->setPC(val); 2262315SN/A checkerCPU->recordPCChange(val); 2272315SN/A } 2282315SN/A 2292680SN/A uint64_t readNextPC() { return actualTC->readNextPC(); } 2302315SN/A 2312315SN/A void setNextPC(uint64_t val) 2322315SN/A { 2332680SN/A actualTC->setNextPC(val); 2342680SN/A checkerTC->setNextPC(val); 2352315SN/A checkerCPU->recordNextPCChange(val); 2362315SN/A } 2372315SN/A 2382680SN/A uint64_t readNextNPC() { return actualTC->readNextNPC(); } 2392669SN/A 2402669SN/A void setNextNPC(uint64_t val) 2412669SN/A { 2422680SN/A actualTC->setNextNPC(val); 2432680SN/A checkerTC->setNextNPC(val); 2442669SN/A checkerCPU->recordNextPCChange(val); 2452669SN/A } 2462669SN/A 2472315SN/A MiscReg readMiscReg(int misc_reg) 2482680SN/A { return actualTC->readMiscReg(misc_reg); } 2492315SN/A 2502315SN/A MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault) 2512680SN/A { return actualTC->readMiscRegWithEffect(misc_reg, fault); } 2522315SN/A 2532315SN/A Fault setMiscReg(int misc_reg, const MiscReg &val) 2542315SN/A { 2552680SN/A checkerTC->setMiscReg(misc_reg, val); 2562680SN/A return actualTC->setMiscReg(misc_reg, val); 2572315SN/A } 2582315SN/A 2592315SN/A Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val) 2602315SN/A { 2612680SN/A checkerTC->setMiscRegWithEffect(misc_reg, val); 2622680SN/A return actualTC->setMiscRegWithEffect(misc_reg, val); 2632315SN/A } 2642315SN/A 2652315SN/A unsigned readStCondFailures() 2662680SN/A { return actualTC->readStCondFailures(); } 2672315SN/A 2682315SN/A void setStCondFailures(unsigned sc_failures) 2692315SN/A { 2702680SN/A checkerTC->setStCondFailures(sc_failures); 2712680SN/A actualTC->setStCondFailures(sc_failures); 2722315SN/A } 2732315SN/A#if FULL_SYSTEM 2742680SN/A bool inPalMode() { return actualTC->inPalMode(); } 2752315SN/A#endif 2762315SN/A 2772315SN/A // @todo: Fix this! 2782680SN/A bool misspeculating() { return actualTC->misspeculating(); } 2792315SN/A 2802315SN/A#if !FULL_SYSTEM 2812680SN/A IntReg getSyscallArg(int i) { return actualTC->getSyscallArg(i); } 2822315SN/A 2832315SN/A // used to shift args for indirect syscall 2842315SN/A void setSyscallArg(int i, IntReg val) 2852315SN/A { 2862680SN/A checkerTC->setSyscallArg(i, val); 2872680SN/A actualTC->setSyscallArg(i, val); 2882315SN/A } 2892315SN/A 2902315SN/A void setSyscallReturn(SyscallReturn return_value) 2912315SN/A { 2922680SN/A checkerTC->setSyscallReturn(return_value); 2932680SN/A actualTC->setSyscallReturn(return_value); 2942315SN/A } 2952315SN/A 2962680SN/A Counter readFuncExeInst() { return actualTC->readFuncExeInst(); } 2972315SN/A#endif 2982669SN/A void changeRegFileContext(RegFile::ContextParam param, 2992669SN/A RegFile::ContextVal val) 3002669SN/A { 3012680SN/A actualTC->changeRegFileContext(param, val); 3022680SN/A checkerTC->changeRegFileContext(param, val); 3032669SN/A } 3042315SN/A}; 3052315SN/A 3062315SN/A#endif // __CPU_CHECKER_EXEC_CONTEXT_HH__ 307