thread_context.hh revision 6022
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
342972Sgblack@eecs.umich.edu#include "arch/types.hh"
352315SN/A#include "cpu/checker/cpu.hh"
362683Sktlim@umich.edu#include "cpu/simple_thread.hh"
372680SN/A#include "cpu/thread_context.hh"
382315SN/A
392315SN/Aclass EndQuiesceEvent;
403548Sgblack@eecs.umich.edunamespace TheISA {
413548Sgblack@eecs.umich.edu    namespace Kernel {
423548Sgblack@eecs.umich.edu        class Statistics;
433548Sgblack@eecs.umich.edu    };
442330SN/A};
452315SN/A
462350SN/A/**
472680SN/A * Derived ThreadContext class for use with the Checker.  The template
482680SN/A * parameter is the ThreadContext class used by the specific CPU being
492683Sktlim@umich.edu * verified.  This CheckerThreadContext is then used by the main CPU
502683Sktlim@umich.edu * in place of its usual ThreadContext class.  It handles updating the
512683Sktlim@umich.edu * checker's state any time state is updated externally through the
522683Sktlim@umich.edu * ThreadContext.
532350SN/A */
542680SN/Atemplate <class TC>
552680SN/Aclass CheckerThreadContext : public ThreadContext
562315SN/A{
572315SN/A  public:
582680SN/A    CheckerThreadContext(TC *actual_tc,
592683Sktlim@umich.edu                         CheckerCPU *checker_cpu)
602683Sktlim@umich.edu        : actualTC(actual_tc), checkerTC(checker_cpu->thread),
612330SN/A          checkerCPU(checker_cpu)
622315SN/A    { }
632315SN/A
642315SN/A  private:
652683Sktlim@umich.edu    /** The main CPU's ThreadContext, or class that implements the
662683Sktlim@umich.edu     * ThreadContext interface. */
672680SN/A    TC *actualTC;
682683Sktlim@umich.edu    /** The checker's own SimpleThread. Will be updated any time
692683Sktlim@umich.edu     * anything uses this ThreadContext to externally update a
702683Sktlim@umich.edu     * thread's state. */
712683Sktlim@umich.edu    SimpleThread *checkerTC;
722683Sktlim@umich.edu    /** Pointer to the checker CPU. */
732315SN/A    CheckerCPU *checkerCPU;
742315SN/A
752315SN/A  public:
762315SN/A
772680SN/A    BaseCPU *getCpuPtr() { return actualTC->getCpuPtr(); }
782315SN/A
792315SN/A    void setCpuId(int id)
802315SN/A    {
812680SN/A        actualTC->setCpuId(id);
822680SN/A        checkerTC->setCpuId(id);
832315SN/A    }
842315SN/A
855712Shsul@eecs.umich.edu    int cpuId() { return actualTC->cpuId(); }
862315SN/A
876022Sgblack@eecs.umich.edu    TheISA::TLB *getITBPtr() { return actualTC->getITBPtr(); }
884997Sgblack@eecs.umich.edu
896022Sgblack@eecs.umich.edu    TheISA::TLB *getDTBPtr() { return actualTC->getDTBPtr(); }
904997Sgblack@eecs.umich.edu
912315SN/A#if FULL_SYSTEM
922680SN/A    System *getSystemPtr() { return actualTC->getSystemPtr(); }
932315SN/A
942680SN/A    PhysicalMemory *getPhysMemPtr() { return actualTC->getPhysMemPtr(); }
952315SN/A
963548Sgblack@eecs.umich.edu    TheISA::Kernel::Statistics *getKernelStats()
973548Sgblack@eecs.umich.edu    { return actualTC->getKernelStats(); }
982690Sktlim@umich.edu
992690Sktlim@umich.edu    FunctionalPort *getPhysPort() { return actualTC->getPhysPort(); }
1002690Sktlim@umich.edu
1015499Ssaidi@eecs.umich.edu    VirtualPort *getVirtPort()
1022690Sktlim@umich.edu    { return actualTC->getVirtPort(); }
1032315SN/A#else
1042690Sktlim@umich.edu    TranslatingPort *getMemPort() { return actualTC->getMemPort(); }
1052690Sktlim@umich.edu
1062680SN/A    Process *getProcessPtr() { return actualTC->getProcessPtr(); }
1072315SN/A#endif
1082315SN/A
1092680SN/A    Status status() const { return actualTC->status(); }
1102315SN/A
1112315SN/A    void setStatus(Status new_status)
1122330SN/A    {
1132680SN/A        actualTC->setStatus(new_status);
1142680SN/A        checkerTC->setStatus(new_status);
1152330SN/A    }
1162315SN/A
1172315SN/A    /// Set the status to Active.  Optional delay indicates number of
1182315SN/A    /// cycles to wait before beginning execution.
1192680SN/A    void activate(int delay = 1) { actualTC->activate(delay); }
1202315SN/A
1212315SN/A    /// Set the status to Suspended.
1222680SN/A    void suspend() { actualTC->suspend(); }
1232315SN/A
1242315SN/A    /// Set the status to Unallocated.
1252887Sktlim@umich.edu    void deallocate(int delay = 0) { actualTC->deallocate(delay); }
1262315SN/A
1272315SN/A    /// Set the status to Halted.
1282680SN/A    void halt() { actualTC->halt(); }
1292315SN/A
1302315SN/A#if FULL_SYSTEM
1312680SN/A    void dumpFuncProfile() { actualTC->dumpFuncProfile(); }
1322315SN/A#endif
1332315SN/A
1342680SN/A    void takeOverFrom(ThreadContext *oldContext)
1352315SN/A    {
1362680SN/A        actualTC->takeOverFrom(oldContext);
1373225Sktlim@umich.edu        checkerTC->copyState(oldContext);
1382315SN/A    }
1392315SN/A
1402680SN/A    void regStats(const std::string &name) { actualTC->regStats(name); }
1412315SN/A
1422680SN/A    void serialize(std::ostream &os) { actualTC->serialize(os); }
1432315SN/A    void unserialize(Checkpoint *cp, const std::string &section)
1442680SN/A    { actualTC->unserialize(cp, section); }
1452315SN/A
1462315SN/A#if FULL_SYSTEM
1472680SN/A    EndQuiesceEvent *getQuiesceEvent() { return actualTC->getQuiesceEvent(); }
1482315SN/A
1492680SN/A    Tick readLastActivate() { return actualTC->readLastActivate(); }
1502680SN/A    Tick readLastSuspend() { return actualTC->readLastSuspend(); }
1512315SN/A
1522680SN/A    void profileClear() { return actualTC->profileClear(); }
1532680SN/A    void profileSample() { return actualTC->profileSample(); }
1542315SN/A#endif
1552315SN/A
1565715Shsul@eecs.umich.edu    int threadId() { return actualTC->threadId(); }
1572315SN/A
1582315SN/A    // @todo: Do I need this?
1592680SN/A    MachInst getInst() { return actualTC->getInst(); }
1602315SN/A
1612315SN/A    // @todo: Do I need this?
1622680SN/A    void copyArchRegs(ThreadContext *tc)
1632315SN/A    {
1642680SN/A        actualTC->copyArchRegs(tc);
1652680SN/A        checkerTC->copyArchRegs(tc);
1662315SN/A    }
1672315SN/A
1682315SN/A    void clearArchRegs()
1692315SN/A    {
1702680SN/A        actualTC->clearArchRegs();
1712680SN/A        checkerTC->clearArchRegs();
1722315SN/A    }
1732315SN/A
1742315SN/A    //
1752315SN/A    // New accessors for new decoder.
1762315SN/A    //
1772315SN/A    uint64_t readIntReg(int reg_idx)
1782680SN/A    { return actualTC->readIntReg(reg_idx); }
1792315SN/A
1802669SN/A    FloatReg readFloatReg(int reg_idx, int width)
1812680SN/A    { return actualTC->readFloatReg(reg_idx, width); }
1822315SN/A
1832669SN/A    FloatReg readFloatReg(int reg_idx)
1842680SN/A    { return actualTC->readFloatReg(reg_idx); }
1852315SN/A
1862669SN/A    FloatRegBits readFloatRegBits(int reg_idx, int width)
1872680SN/A    { return actualTC->readFloatRegBits(reg_idx, width); }
1882669SN/A
1892669SN/A    FloatRegBits readFloatRegBits(int reg_idx)
1902680SN/A    { return actualTC->readFloatRegBits(reg_idx); }
1912315SN/A
1922315SN/A    void setIntReg(int reg_idx, uint64_t val)
1932315SN/A    {
1942680SN/A        actualTC->setIntReg(reg_idx, val);
1952680SN/A        checkerTC->setIntReg(reg_idx, val);
1962315SN/A    }
1972315SN/A
1982669SN/A    void setFloatReg(int reg_idx, FloatReg val, int width)
1992315SN/A    {
2002680SN/A        actualTC->setFloatReg(reg_idx, val, width);
2012680SN/A        checkerTC->setFloatReg(reg_idx, val, width);
2022315SN/A    }
2032315SN/A
2042669SN/A    void setFloatReg(int reg_idx, FloatReg val)
2052315SN/A    {
2062680SN/A        actualTC->setFloatReg(reg_idx, val);
2072680SN/A        checkerTC->setFloatReg(reg_idx, val);
2082315SN/A    }
2092315SN/A
2102669SN/A    void setFloatRegBits(int reg_idx, FloatRegBits val, int width)
2112315SN/A    {
2122680SN/A        actualTC->setFloatRegBits(reg_idx, val, width);
2132680SN/A        checkerTC->setFloatRegBits(reg_idx, val, width);
2142669SN/A    }
2152669SN/A
2162669SN/A    void setFloatRegBits(int reg_idx, FloatRegBits val)
2172669SN/A    {
2182680SN/A        actualTC->setFloatRegBits(reg_idx, val);
2192680SN/A        checkerTC->setFloatRegBits(reg_idx, val);
2202315SN/A    }
2212315SN/A
2222680SN/A    uint64_t readPC() { return actualTC->readPC(); }
2232315SN/A
2242315SN/A    void setPC(uint64_t val)
2252315SN/A    {
2262680SN/A        actualTC->setPC(val);
2272680SN/A        checkerTC->setPC(val);
2282315SN/A        checkerCPU->recordPCChange(val);
2292315SN/A    }
2302315SN/A
2312680SN/A    uint64_t readNextPC() { return actualTC->readNextPC(); }
2322315SN/A
2332315SN/A    void setNextPC(uint64_t val)
2342315SN/A    {
2352680SN/A        actualTC->setNextPC(val);
2362680SN/A        checkerTC->setNextPC(val);
2372315SN/A        checkerCPU->recordNextPCChange(val);
2382315SN/A    }
2392315SN/A
2402680SN/A    uint64_t readNextNPC() { return actualTC->readNextNPC(); }
2412669SN/A
2422669SN/A    void setNextNPC(uint64_t val)
2432669SN/A    {
2442680SN/A        actualTC->setNextNPC(val);
2452680SN/A        checkerTC->setNextNPC(val);
2462669SN/A        checkerCPU->recordNextPCChange(val);
2472669SN/A    }
2482669SN/A
2494172Ssaidi@eecs.umich.edu    MiscReg readMiscRegNoEffect(int misc_reg)
2504172Ssaidi@eecs.umich.edu    { return actualTC->readMiscRegNoEffect(misc_reg); }
2514172Ssaidi@eecs.umich.edu
2522315SN/A    MiscReg readMiscReg(int misc_reg)
2532680SN/A    { return actualTC->readMiscReg(misc_reg); }
2542315SN/A
2554172Ssaidi@eecs.umich.edu    void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
2564172Ssaidi@eecs.umich.edu    {
2574172Ssaidi@eecs.umich.edu        checkerTC->setMiscRegNoEffect(misc_reg, val);
2584172Ssaidi@eecs.umich.edu        actualTC->setMiscRegNoEffect(misc_reg, val);
2594172Ssaidi@eecs.umich.edu    }
2602315SN/A
2613468Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const MiscReg &val)
2622315SN/A    {
2632680SN/A        checkerTC->setMiscReg(misc_reg, val);
2643468Sgblack@eecs.umich.edu        actualTC->setMiscReg(misc_reg, val);
2652315SN/A    }
2662315SN/A
2672315SN/A    unsigned readStCondFailures()
2682680SN/A    { return actualTC->readStCondFailures(); }
2692315SN/A
2702315SN/A    void setStCondFailures(unsigned sc_failures)
2712315SN/A    {
2722680SN/A        checkerTC->setStCondFailures(sc_failures);
2732680SN/A        actualTC->setStCondFailures(sc_failures);
2742315SN/A    }
2752315SN/A
2762315SN/A    // @todo: Fix this!
2772680SN/A    bool misspeculating() { return actualTC->misspeculating(); }
2782315SN/A
2792315SN/A#if !FULL_SYSTEM
2802680SN/A    Counter readFuncExeInst() { return actualTC->readFuncExeInst(); }
2812315SN/A#endif
2822315SN/A};
2832315SN/A
2842315SN/A#endif // __CPU_CHECKER_EXEC_CONTEXT_HH__
285