thread_context.hh revision 9020
12330SN/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 *
142330SN/A * Copyright (c) 2006 The Regents of The University of Michigan
152330SN/A * All rights reserved.
162330SN/A *
172330SN/A * Redistribution and use in source and binary forms, with or without
182330SN/A * modification, are permitted provided that the following conditions are
192330SN/A * met: redistributions of source code must retain the above copyright
202330SN/A * notice, this list of conditions and the following disclaimer;
212330SN/A * redistributions in binary form must reproduce the above copyright
222330SN/A * notice, this list of conditions and the following disclaimer in the
232330SN/A * documentation and/or other materials provided with the distribution;
242330SN/A * neither the name of the copyright holders nor the names of its
252330SN/A * contributors may be used to endorse or promote products derived from
262330SN/A * this software without specific prior written permission.
272330SN/A *
282330SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292330SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302330SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312330SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322330SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332330SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342330SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352330SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362330SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372330SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382330SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392689Sktlim@umich.edu *
402689Sktlim@umich.edu * Authors: Kevin Lim
412330SN/A */
422330SN/A
432683Sktlim@umich.edu#ifndef __CPU_CHECKER_THREAD_CONTEXT_HH__
442683Sktlim@umich.edu#define __CPU_CHECKER_THREAD_CONTEXT_HH__
452315SN/A
462972Sgblack@eecs.umich.edu#include "arch/types.hh"
476658Snate@binkert.org#include "config/the_isa.hh"
482315SN/A#include "cpu/checker/cpu.hh"
492683Sktlim@umich.edu#include "cpu/simple_thread.hh"
502680SN/A#include "cpu/thread_context.hh"
518733Sgeoffrey.blake@arm.com#include "debug/Checker.hh"
522315SN/A
532315SN/Aclass EndQuiesceEvent;
543548Sgblack@eecs.umich.edunamespace TheISA {
553548Sgblack@eecs.umich.edu    namespace Kernel {
563548Sgblack@eecs.umich.edu        class Statistics;
573548Sgblack@eecs.umich.edu    };
589020Sgblack@eecs.umich.edu    class Decoder;
592330SN/A};
602315SN/A
612350SN/A/**
622680SN/A * Derived ThreadContext class for use with the Checker.  The template
632680SN/A * parameter is the ThreadContext class used by the specific CPU being
642683Sktlim@umich.edu * verified.  This CheckerThreadContext is then used by the main CPU
652683Sktlim@umich.edu * in place of its usual ThreadContext class.  It handles updating the
662683Sktlim@umich.edu * checker's state any time state is updated externally through the
672683Sktlim@umich.edu * ThreadContext.
682350SN/A */
692680SN/Atemplate <class TC>
702680SN/Aclass CheckerThreadContext : public ThreadContext
712315SN/A{
722315SN/A  public:
732680SN/A    CheckerThreadContext(TC *actual_tc,
742683Sktlim@umich.edu                         CheckerCPU *checker_cpu)
752683Sktlim@umich.edu        : actualTC(actual_tc), checkerTC(checker_cpu->thread),
762330SN/A          checkerCPU(checker_cpu)
772315SN/A    { }
782315SN/A
792315SN/A  private:
802683Sktlim@umich.edu    /** The main CPU's ThreadContext, or class that implements the
812683Sktlim@umich.edu     * ThreadContext interface. */
822680SN/A    TC *actualTC;
832683Sktlim@umich.edu    /** The checker's own SimpleThread. Will be updated any time
842683Sktlim@umich.edu     * anything uses this ThreadContext to externally update a
852683Sktlim@umich.edu     * thread's state. */
862683Sktlim@umich.edu    SimpleThread *checkerTC;
872683Sktlim@umich.edu    /** Pointer to the checker CPU. */
882315SN/A    CheckerCPU *checkerCPU;
892315SN/A
902315SN/A  public:
912315SN/A
922680SN/A    BaseCPU *getCpuPtr() { return actualTC->getCpuPtr(); }
932315SN/A
948733Sgeoffrey.blake@arm.com    int cpuId() { return actualTC->cpuId(); }
958733Sgeoffrey.blake@arm.com
968733Sgeoffrey.blake@arm.com    int contextId() { return actualTC->contextId(); }
978733Sgeoffrey.blake@arm.com
988733Sgeoffrey.blake@arm.com    void setContextId(int id)
992315SN/A    {
1008733Sgeoffrey.blake@arm.com       actualTC->setContextId(id);
1018733Sgeoffrey.blake@arm.com       checkerTC->setContextId(id);
1022315SN/A    }
1032315SN/A
1048733Sgeoffrey.blake@arm.com    /** Returns this thread's ID number. */
1058733Sgeoffrey.blake@arm.com    int threadId() { return actualTC->threadId(); }
1068733Sgeoffrey.blake@arm.com    void setThreadId(int id)
1078733Sgeoffrey.blake@arm.com    {
1088733Sgeoffrey.blake@arm.com        checkerTC->setThreadId(id);
1098733Sgeoffrey.blake@arm.com        actualTC->setThreadId(id);
1108733Sgeoffrey.blake@arm.com    }
1112315SN/A
1126022Sgblack@eecs.umich.edu    TheISA::TLB *getITBPtr() { return actualTC->getITBPtr(); }
1134997Sgblack@eecs.umich.edu
1146022Sgblack@eecs.umich.edu    TheISA::TLB *getDTBPtr() { return actualTC->getDTBPtr(); }
1154997Sgblack@eecs.umich.edu
1168887Sgeoffrey.blake@arm.com    CheckerCPU *getCheckerCpuPtr()
1178887Sgeoffrey.blake@arm.com    {
1188887Sgeoffrey.blake@arm.com        return checkerCPU;
1198887Sgeoffrey.blake@arm.com    }
1208733Sgeoffrey.blake@arm.com
1219020Sgblack@eecs.umich.edu    TheISA::Decoder *getDecoderPtr() { return actualTC->getDecoderPtr(); }
1228733Sgeoffrey.blake@arm.com
1232680SN/A    System *getSystemPtr() { return actualTC->getSystemPtr(); }
1242315SN/A
1253548Sgblack@eecs.umich.edu    TheISA::Kernel::Statistics *getKernelStats()
1263548Sgblack@eecs.umich.edu    { return actualTC->getKernelStats(); }
1272690Sktlim@umich.edu
1287679Sgblack@eecs.umich.edu    Process *getProcessPtr() { return actualTC->getProcessPtr(); }
1297679Sgblack@eecs.umich.edu
1308852Sandreas.hansson@arm.com    PortProxy &getPhysProxy() { return actualTC->getPhysProxy(); }
1312690Sktlim@umich.edu
1328852Sandreas.hansson@arm.com    FSTranslatingPortProxy &getVirtProxy()
1338706Sandreas.hansson@arm.com    { return actualTC->getVirtProxy(); }
1348733Sgeoffrey.blake@arm.com
1358733Sgeoffrey.blake@arm.com    void initMemProxies(ThreadContext *tc)
1368733Sgeoffrey.blake@arm.com    { actualTC->initMemProxies(tc); }
1378733Sgeoffrey.blake@arm.com
1388733Sgeoffrey.blake@arm.com    void connectMemPorts(ThreadContext *tc)
1398733Sgeoffrey.blake@arm.com    {
1408733Sgeoffrey.blake@arm.com        actualTC->connectMemPorts(tc);
1418733Sgeoffrey.blake@arm.com    }
1428809Sgblack@eecs.umich.edu
1438852Sandreas.hansson@arm.com    SETranslatingPortProxy &getMemProxy() { return actualTC->getMemProxy(); }
1442690Sktlim@umich.edu
1458733Sgeoffrey.blake@arm.com    /** Executes a syscall in SE mode. */
1468733Sgeoffrey.blake@arm.com    void syscall(int64_t callnum)
1478733Sgeoffrey.blake@arm.com    { return actualTC->syscall(callnum); }
1482315SN/A
1492680SN/A    Status status() const { return actualTC->status(); }
1502315SN/A
1512315SN/A    void setStatus(Status new_status)
1522330SN/A    {
1532680SN/A        actualTC->setStatus(new_status);
1542680SN/A        checkerTC->setStatus(new_status);
1552330SN/A    }
1562315SN/A
1572315SN/A    /// Set the status to Active.  Optional delay indicates number of
1582315SN/A    /// cycles to wait before beginning execution.
1592680SN/A    void activate(int delay = 1) { actualTC->activate(delay); }
1602315SN/A
1612315SN/A    /// Set the status to Suspended.
1628733Sgeoffrey.blake@arm.com    void suspend(int delay) { actualTC->suspend(delay); }
1632315SN/A
1642315SN/A    /// Set the status to Halted.
1658733Sgeoffrey.blake@arm.com    void halt(int delay) { actualTC->halt(delay); }
1662315SN/A
1672680SN/A    void dumpFuncProfile() { actualTC->dumpFuncProfile(); }
1682315SN/A
1692680SN/A    void takeOverFrom(ThreadContext *oldContext)
1702315SN/A    {
1712680SN/A        actualTC->takeOverFrom(oldContext);
1723225Sktlim@umich.edu        checkerTC->copyState(oldContext);
1732315SN/A    }
1742315SN/A
1758733Sgeoffrey.blake@arm.com    void regStats(const std::string &name)
1768733Sgeoffrey.blake@arm.com    {
1778733Sgeoffrey.blake@arm.com        actualTC->regStats(name);
1788733Sgeoffrey.blake@arm.com        checkerTC->regStats(name);
1798733Sgeoffrey.blake@arm.com    }
1802315SN/A
1812680SN/A    void serialize(std::ostream &os) { actualTC->serialize(os); }
1822315SN/A    void unserialize(Checkpoint *cp, const std::string &section)
1832680SN/A    { actualTC->unserialize(cp, section); }
1842315SN/A
1852680SN/A    EndQuiesceEvent *getQuiesceEvent() { return actualTC->getQuiesceEvent(); }
1862315SN/A
1872680SN/A    Tick readLastActivate() { return actualTC->readLastActivate(); }
1882680SN/A    Tick readLastSuspend() { return actualTC->readLastSuspend(); }
1892315SN/A
1902680SN/A    void profileClear() { return actualTC->profileClear(); }
1912680SN/A    void profileSample() { return actualTC->profileSample(); }
1922315SN/A
1932315SN/A    // @todo: Do I need this?
1942680SN/A    void copyArchRegs(ThreadContext *tc)
1952315SN/A    {
1962680SN/A        actualTC->copyArchRegs(tc);
1972680SN/A        checkerTC->copyArchRegs(tc);
1982315SN/A    }
1992315SN/A
2002315SN/A    void clearArchRegs()
2012315SN/A    {
2022680SN/A        actualTC->clearArchRegs();
2032680SN/A        checkerTC->clearArchRegs();
2042315SN/A    }
2052315SN/A
2062315SN/A    //
2072315SN/A    // New accessors for new decoder.
2082315SN/A    //
2092315SN/A    uint64_t readIntReg(int reg_idx)
2102680SN/A    { return actualTC->readIntReg(reg_idx); }
2112315SN/A
2122669SN/A    FloatReg readFloatReg(int reg_idx)
2132680SN/A    { return actualTC->readFloatReg(reg_idx); }
2142315SN/A
2152669SN/A    FloatRegBits readFloatRegBits(int reg_idx)
2162680SN/A    { return actualTC->readFloatRegBits(reg_idx); }
2172315SN/A
2182315SN/A    void setIntReg(int reg_idx, uint64_t val)
2192315SN/A    {
2202680SN/A        actualTC->setIntReg(reg_idx, val);
2212680SN/A        checkerTC->setIntReg(reg_idx, val);
2222315SN/A    }
2232315SN/A
2242669SN/A    void setFloatReg(int reg_idx, FloatReg val)
2252315SN/A    {
2262680SN/A        actualTC->setFloatReg(reg_idx, val);
2272680SN/A        checkerTC->setFloatReg(reg_idx, val);
2282315SN/A    }
2292315SN/A
2302669SN/A    void setFloatRegBits(int reg_idx, FloatRegBits val)
2312669SN/A    {
2322680SN/A        actualTC->setFloatRegBits(reg_idx, val);
2332680SN/A        checkerTC->setFloatRegBits(reg_idx, val);
2342315SN/A    }
2352315SN/A
2368733Sgeoffrey.blake@arm.com    /** Reads this thread's PC state. */
2378733Sgeoffrey.blake@arm.com    TheISA::PCState pcState()
2388733Sgeoffrey.blake@arm.com    { return actualTC->pcState(); }
2392315SN/A
2408733Sgeoffrey.blake@arm.com    /** Sets this thread's PC state. */
2418733Sgeoffrey.blake@arm.com    void pcState(const TheISA::PCState &val)
2422315SN/A    {
2438733Sgeoffrey.blake@arm.com        DPRINTF(Checker, "Changing PC to %s, old PC %s\n",
2448733Sgeoffrey.blake@arm.com                         val, checkerTC->pcState());
2458733Sgeoffrey.blake@arm.com        checkerTC->pcState(val);
2462315SN/A        checkerCPU->recordPCChange(val);
2478733Sgeoffrey.blake@arm.com        return actualTC->pcState(val);
2482315SN/A    }
2492315SN/A
2508733Sgeoffrey.blake@arm.com    void pcStateNoRecord(const TheISA::PCState &val)
2512315SN/A    {
2528733Sgeoffrey.blake@arm.com        return actualTC->pcState(val);
2532315SN/A    }
2542315SN/A
2558733Sgeoffrey.blake@arm.com    /** Reads this thread's PC. */
2568733Sgeoffrey.blake@arm.com    Addr instAddr()
2578733Sgeoffrey.blake@arm.com    { return actualTC->instAddr(); }
2582669SN/A
2598733Sgeoffrey.blake@arm.com    /** Reads this thread's next PC. */
2608733Sgeoffrey.blake@arm.com    Addr nextInstAddr()
2618733Sgeoffrey.blake@arm.com    { return actualTC->nextInstAddr(); }
2628733Sgeoffrey.blake@arm.com
2638733Sgeoffrey.blake@arm.com    /** Reads this thread's next PC. */
2648733Sgeoffrey.blake@arm.com    MicroPC microPC()
2658733Sgeoffrey.blake@arm.com    { return actualTC->microPC(); }
2662669SN/A
2674172Ssaidi@eecs.umich.edu    MiscReg readMiscRegNoEffect(int misc_reg)
2684172Ssaidi@eecs.umich.edu    { return actualTC->readMiscRegNoEffect(misc_reg); }
2694172Ssaidi@eecs.umich.edu
2702315SN/A    MiscReg readMiscReg(int misc_reg)
2712680SN/A    { return actualTC->readMiscReg(misc_reg); }
2722315SN/A
2734172Ssaidi@eecs.umich.edu    void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
2744172Ssaidi@eecs.umich.edu    {
2758733Sgeoffrey.blake@arm.com        DPRINTF(Checker, "Setting misc reg with no effect: %d to both Checker"
2768733Sgeoffrey.blake@arm.com                         " and O3..\n", misc_reg);
2774172Ssaidi@eecs.umich.edu        checkerTC->setMiscRegNoEffect(misc_reg, val);
2784172Ssaidi@eecs.umich.edu        actualTC->setMiscRegNoEffect(misc_reg, val);
2794172Ssaidi@eecs.umich.edu    }
2802315SN/A
2813468Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const MiscReg &val)
2822315SN/A    {
2838733Sgeoffrey.blake@arm.com        DPRINTF(Checker, "Setting misc reg with effect: %d to both Checker"
2848733Sgeoffrey.blake@arm.com                         " and O3..\n", misc_reg);
2852680SN/A        checkerTC->setMiscReg(misc_reg, val);
2863468Sgblack@eecs.umich.edu        actualTC->setMiscReg(misc_reg, val);
2872315SN/A    }
2882315SN/A
2898733Sgeoffrey.blake@arm.com    int flattenIntIndex(int reg) { return actualTC->flattenIntIndex(reg); }
2908733Sgeoffrey.blake@arm.com    int flattenFloatIndex(int reg) { return actualTC->flattenFloatIndex(reg); }
2918733Sgeoffrey.blake@arm.com
2922315SN/A    unsigned readStCondFailures()
2932680SN/A    { return actualTC->readStCondFailures(); }
2942315SN/A
2952315SN/A    void setStCondFailures(unsigned sc_failures)
2962315SN/A    {
2972680SN/A        actualTC->setStCondFailures(sc_failures);
2982315SN/A    }
2992315SN/A
3002315SN/A    // @todo: Fix this!
3012680SN/A    bool misspeculating() { return actualTC->misspeculating(); }
3022315SN/A
3032680SN/A    Counter readFuncExeInst() { return actualTC->readFuncExeInst(); }
3042315SN/A};
3052315SN/A
3062315SN/A#endif // __CPU_CHECKER_EXEC_CONTEXT_HH__
307