thread_context.hh revision 13641
12SN/A/* 213610Sgiacomo.gabrielli@arm.com * Copyright (c) 2011-2012, 2016-2018 ARM Limited 39920Syasuko.eckert@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 48733Sgeoffrey.blake@arm.com * All rights reserved 58733Sgeoffrey.blake@arm.com * 68733Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall 78733Sgeoffrey.blake@arm.com * not be construed as granting a license to any other intellectual 88733Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating 98733Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software 108733Sgeoffrey.blake@arm.com * licensed hereunder. You may use the software subject to the license 118733Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated 128733Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software, 138733Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form. 148733Sgeoffrey.blake@arm.com * 152190SN/A * Copyright (c) 2006 The Regents of The University of Michigan 162SN/A * All rights reserved. 172SN/A * 182SN/A * Redistribution and use in source and binary forms, with or without 192SN/A * modification, are permitted provided that the following conditions are 202SN/A * met: redistributions of source code must retain the above copyright 212SN/A * notice, this list of conditions and the following disclaimer; 222SN/A * redistributions in binary form must reproduce the above copyright 232SN/A * notice, this list of conditions and the following disclaimer in the 242SN/A * documentation and/or other materials provided with the distribution; 252SN/A * neither the name of the copyright holders nor the names of its 262SN/A * contributors may be used to endorse or promote products derived from 272SN/A * this software without specific prior written permission. 282SN/A * 292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665SN/A * 412665SN/A * Authors: Kevin Lim 422SN/A */ 432SN/A 442680Sktlim@umich.edu#ifndef __CPU_THREAD_CONTEXT_HH__ 452680Sktlim@umich.edu#define __CPU_THREAD_CONTEXT_HH__ 462SN/A 478229Snate@binkert.org#include <iostream> 487680Sgblack@eecs.umich.edu#include <string> 497680Sgblack@eecs.umich.edu 506329Sgblack@eecs.umich.edu#include "arch/registers.hh" 513453Sgblack@eecs.umich.edu#include "arch/types.hh" 526216Snate@binkert.org#include "base/types.hh" 536658Snate@binkert.org#include "config/the_isa.hh" 5412104Snathanael.premillieu@arm.com#include "cpu/reg_class.hh" 552SN/A 562190SN/A// @todo: Figure out a more architecture independent way to obtain the ITB and 572190SN/A// DTB pointers. 583453Sgblack@eecs.umich.edunamespace TheISA 593453Sgblack@eecs.umich.edu{ 609020Sgblack@eecs.umich.edu class Decoder; 613453Sgblack@eecs.umich.edu} 622190SN/Aclass BaseCPU; 6312406Sgabeblack@google.comclass BaseTLB; 648887Sgeoffrey.blake@arm.comclass CheckerCPU; 657680Sgblack@eecs.umich.educlass Checkpoint; 662313SN/Aclass EndQuiesceEvent; 678706Sandreas.hansson@arm.comclass SETranslatingPortProxy; 688706Sandreas.hansson@arm.comclass FSTranslatingPortProxy; 698706Sandreas.hansson@arm.comclass PortProxy; 702190SN/Aclass Process; 712190SN/Aclass System; 723548Sgblack@eecs.umich.edunamespace TheISA { 733548Sgblack@eecs.umich.edu namespace Kernel { 743548Sgblack@eecs.umich.edu class Statistics; 758902Sandreas.hansson@arm.com } 768902Sandreas.hansson@arm.com} 772SN/A 782680Sktlim@umich.edu/** 792680Sktlim@umich.edu * ThreadContext is the external interface to all thread state for 802680Sktlim@umich.edu * anything outside of the CPU. It provides all accessor methods to 812680Sktlim@umich.edu * state that might be needed by external objects, ranging from 822680Sktlim@umich.edu * register values to things such as kernel stats. It is an abstract 832680Sktlim@umich.edu * base class; the CPU can create its own ThreadContext by either 842680Sktlim@umich.edu * deriving from it, or using the templated ProxyThreadContext. 852680Sktlim@umich.edu * 862680Sktlim@umich.edu * The ThreadContext is slightly different than the ExecContext. The 872680Sktlim@umich.edu * ThreadContext provides access to an individual thread's state; an 882680Sktlim@umich.edu * ExecContext provides ISA access to the CPU (meaning it is 892682Sktlim@umich.edu * implicitly multithreaded on SMT systems). Additionally the 902680Sktlim@umich.edu * ThreadState is an abstract class that exactly defines the 912680Sktlim@umich.edu * interface; the ExecContext is a more implicit interface that must 922680Sktlim@umich.edu * be implemented so that the ISA can access whatever state it needs. 932680Sktlim@umich.edu */ 942680Sktlim@umich.educlass ThreadContext 952SN/A{ 962107SN/A protected: 972107SN/A typedef TheISA::MachInst MachInst; 9812109SRekai.GonzalezAlberquilla@arm.com using VecRegContainer = TheISA::VecRegContainer; 9912109SRekai.GonzalezAlberquilla@arm.com using VecElem = TheISA::VecElem; 10013610Sgiacomo.gabrielli@arm.com using VecPredRegContainer = TheISA::VecPredRegContainer; 10113610Sgiacomo.gabrielli@arm.com 1022SN/A public: 1036029Ssteve.reinhardt@amd.com 104246SN/A enum Status 105246SN/A { 106246SN/A /// Running. Instructions should be executed only when 107246SN/A /// the context is in this state. 108246SN/A Active, 109246SN/A 110246SN/A /// Temporarily inactive. Entered while waiting for 1112190SN/A /// synchronization, etc. 112246SN/A Suspended, 113246SN/A 11413641Sqtt2@cornell.edu /// Trying to exit and waiting for an event to completely exit. 11513641Sqtt2@cornell.edu /// Entered when target executes an exit syscall. 11613641Sqtt2@cornell.edu Halting, 11713641Sqtt2@cornell.edu 118246SN/A /// Permanently shut down. Entered when target executes 119246SN/A /// m5exit pseudo-instruction. When all contexts enter 120246SN/A /// this state, the simulation will terminate. 121246SN/A Halted 122246SN/A }; 1232SN/A 1242680Sktlim@umich.edu virtual ~ThreadContext() { }; 1252423SN/A 1262190SN/A virtual BaseCPU *getCpuPtr() = 0; 127180SN/A 12810110Sandreas.hansson@arm.com virtual int cpuId() const = 0; 1292190SN/A 13010190Sakash.bagdia@arm.com virtual uint32_t socketId() const = 0; 13110190Sakash.bagdia@arm.com 13210110Sandreas.hansson@arm.com virtual int threadId() const = 0; 1335715Shsul@eecs.umich.edu 1345715Shsul@eecs.umich.edu virtual void setThreadId(int id) = 0; 1355714Shsul@eecs.umich.edu 13610110Sandreas.hansson@arm.com virtual int contextId() const = 0; 1375714Shsul@eecs.umich.edu 1385714Shsul@eecs.umich.edu virtual void setContextId(int id) = 0; 1395714Shsul@eecs.umich.edu 14012406Sgabeblack@google.com virtual BaseTLB *getITBPtr() = 0; 1412190SN/A 14212406Sgabeblack@google.com virtual BaseTLB *getDTBPtr() = 0; 1432521SN/A 1448887Sgeoffrey.blake@arm.com virtual CheckerCPU *getCheckerCpuPtr() = 0; 1458733Sgeoffrey.blake@arm.com 1469020Sgblack@eecs.umich.edu virtual TheISA::Decoder *getDecoderPtr() = 0; 1478541Sgblack@eecs.umich.edu 1484997Sgblack@eecs.umich.edu virtual System *getSystemPtr() = 0; 1494997Sgblack@eecs.umich.edu 1503548Sgblack@eecs.umich.edu virtual TheISA::Kernel::Statistics *getKernelStats() = 0; 1512654SN/A 1528852Sandreas.hansson@arm.com virtual PortProxy &getPhysProxy() = 0; 1532521SN/A 1548852Sandreas.hansson@arm.com virtual FSTranslatingPortProxy &getVirtProxy() = 0; 1553673Srdreslin@umich.edu 1568706Sandreas.hansson@arm.com /** 1578706Sandreas.hansson@arm.com * Initialise the physical and virtual port proxies and tie them to 1588706Sandreas.hansson@arm.com * the data port of the CPU. 1598706Sandreas.hansson@arm.com * 1608706Sandreas.hansson@arm.com * tc ThreadContext for the virtual-to-physical translation 1618706Sandreas.hansson@arm.com */ 1628706Sandreas.hansson@arm.com virtual void initMemProxies(ThreadContext *tc) = 0; 1638799Sgblack@eecs.umich.edu 1648852Sandreas.hansson@arm.com virtual SETranslatingPortProxy &getMemProxy() = 0; 1652518SN/A 1662190SN/A virtual Process *getProcessPtr() = 0; 1672190SN/A 16811886Sbrandon.potter@amd.com virtual void setProcessPtr(Process *p) = 0; 16911886Sbrandon.potter@amd.com 1702190SN/A virtual Status status() const = 0; 1712159SN/A 1722235SN/A virtual void setStatus(Status new_status) = 0; 1732103SN/A 17410407Smitch.hayenga@arm.com /// Set the status to Active. 17510407Smitch.hayenga@arm.com virtual void activate() = 0; 176393SN/A 177393SN/A /// Set the status to Suspended. 17810407Smitch.hayenga@arm.com virtual void suspend() = 0; 179393SN/A 180393SN/A /// Set the status to Halted. 18110407Smitch.hayenga@arm.com virtual void halt() = 0; 1822159SN/A 18311627Smichael.lebeane@amd.com /// Quiesce thread context 18411627Smichael.lebeane@amd.com void quiesce(); 18511627Smichael.lebeane@amd.com 18611627Smichael.lebeane@amd.com /// Quiesce, suspend, and schedule activate at resume 18711627Smichael.lebeane@amd.com void quiesceTick(Tick resume); 18811627Smichael.lebeane@amd.com 1892190SN/A virtual void dumpFuncProfile() = 0; 1902159SN/A 1912680Sktlim@umich.edu virtual void takeOverFrom(ThreadContext *old_context) = 0; 1922159SN/A 1932190SN/A virtual void regStats(const std::string &name) = 0; 1942159SN/A 1952313SN/A virtual EndQuiesceEvent *getQuiesceEvent() = 0; 1962235SN/A 1972235SN/A // Not necessarily the best location for these... 1982235SN/A // Having an extra function just to read these is obnoxious 1992235SN/A virtual Tick readLastActivate() = 0; 2002235SN/A virtual Tick readLastSuspend() = 0; 2012254SN/A 2022254SN/A virtual void profileClear() = 0; 2032254SN/A virtual void profileSample() = 0; 2042235SN/A 2052680Sktlim@umich.edu virtual void copyArchRegs(ThreadContext *tc) = 0; 2062159SN/A 2072190SN/A virtual void clearArchRegs() = 0; 2082159SN/A 2092159SN/A // 2102159SN/A // New accessors for new decoder. 2112159SN/A // 21213557Sgabeblack@google.com virtual RegVal readIntReg(int reg_idx) = 0; 2132159SN/A 21413611Sgabeblack@google.com virtual RegVal readFloatReg(int reg_idx) = 0; 2152159SN/A 21612109SRekai.GonzalezAlberquilla@arm.com virtual const VecRegContainer& readVecReg(const RegId& reg) const = 0; 21712109SRekai.GonzalezAlberquilla@arm.com virtual VecRegContainer& getWritableVecReg(const RegId& reg) = 0; 21812109SRekai.GonzalezAlberquilla@arm.com 21912109SRekai.GonzalezAlberquilla@arm.com /** Vector Register Lane Interfaces. */ 22012109SRekai.GonzalezAlberquilla@arm.com /** @{ */ 22112109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 8bit operand. */ 22212109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane8 22312109SRekai.GonzalezAlberquilla@arm.com readVec8BitLaneReg(const RegId& reg) const = 0; 22412109SRekai.GonzalezAlberquilla@arm.com 22512109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 16bit operand. */ 22612109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane16 22712109SRekai.GonzalezAlberquilla@arm.com readVec16BitLaneReg(const RegId& reg) const = 0; 22812109SRekai.GonzalezAlberquilla@arm.com 22912109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 32bit operand. */ 23012109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane32 23112109SRekai.GonzalezAlberquilla@arm.com readVec32BitLaneReg(const RegId& reg) const = 0; 23212109SRekai.GonzalezAlberquilla@arm.com 23312109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 64bit operand. */ 23412109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane64 23512109SRekai.GonzalezAlberquilla@arm.com readVec64BitLaneReg(const RegId& reg) const = 0; 23612109SRekai.GonzalezAlberquilla@arm.com 23712109SRekai.GonzalezAlberquilla@arm.com /** Write a lane of the destination vector register. */ 23812109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 23912109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::Byte>& val) = 0; 24012109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 24112109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::TwoByte>& val) = 0; 24212109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 24312109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::FourByte>& val) = 0; 24412109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 24512109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::EightByte>& val) = 0; 24612109SRekai.GonzalezAlberquilla@arm.com /** @} */ 24712109SRekai.GonzalezAlberquilla@arm.com 24812109SRekai.GonzalezAlberquilla@arm.com virtual const VecElem& readVecElem(const RegId& reg) const = 0; 24912109SRekai.GonzalezAlberquilla@arm.com 25013610Sgiacomo.gabrielli@arm.com virtual const VecPredRegContainer& readVecPredReg(const RegId& reg) 25113610Sgiacomo.gabrielli@arm.com const = 0; 25213610Sgiacomo.gabrielli@arm.com virtual VecPredRegContainer& getWritableVecPredReg(const RegId& reg) = 0; 25313610Sgiacomo.gabrielli@arm.com 25413622Sgabeblack@google.com virtual RegVal readCCReg(int reg_idx) = 0; 2559920Syasuko.eckert@amd.com 25613557Sgabeblack@google.com virtual void setIntReg(int reg_idx, RegVal val) = 0; 2572159SN/A 25813611Sgabeblack@google.com virtual void setFloatReg(int reg_idx, RegVal val) = 0; 2592455SN/A 26012109SRekai.GonzalezAlberquilla@arm.com virtual void setVecReg(const RegId& reg, const VecRegContainer& val) = 0; 26112109SRekai.GonzalezAlberquilla@arm.com 26212109SRekai.GonzalezAlberquilla@arm.com virtual void setVecElem(const RegId& reg, const VecElem& val) = 0; 26312109SRekai.GonzalezAlberquilla@arm.com 26413610Sgiacomo.gabrielli@arm.com virtual void setVecPredReg(const RegId& reg, 26513610Sgiacomo.gabrielli@arm.com const VecPredRegContainer& val) = 0; 26613610Sgiacomo.gabrielli@arm.com 26713622Sgabeblack@google.com virtual void setCCReg(int reg_idx, RegVal val) = 0; 2689920Syasuko.eckert@amd.com 2697720Sgblack@eecs.umich.edu virtual TheISA::PCState pcState() = 0; 2702159SN/A 2717720Sgblack@eecs.umich.edu virtual void pcState(const TheISA::PCState &val) = 0; 2722159SN/A 27311886Sbrandon.potter@amd.com void 27411886Sbrandon.potter@amd.com setNPC(Addr val) 27511886Sbrandon.potter@amd.com { 27611886Sbrandon.potter@amd.com TheISA::PCState pc_state = pcState(); 27711886Sbrandon.potter@amd.com pc_state.setNPC(val); 27811886Sbrandon.potter@amd.com pcState(pc_state); 27911886Sbrandon.potter@amd.com } 28011886Sbrandon.potter@amd.com 2818733Sgeoffrey.blake@arm.com virtual void pcStateNoRecord(const TheISA::PCState &val) = 0; 2828733Sgeoffrey.blake@arm.com 2837720Sgblack@eecs.umich.edu virtual Addr instAddr() = 0; 2842159SN/A 2857720Sgblack@eecs.umich.edu virtual Addr nextInstAddr() = 0; 2862159SN/A 2877720Sgblack@eecs.umich.edu virtual MicroPC microPC() = 0; 2885260Sksewell@umich.edu 28913557Sgabeblack@google.com virtual RegVal readMiscRegNoEffect(int misc_reg) const = 0; 2904172Ssaidi@eecs.umich.edu 29113557Sgabeblack@google.com virtual RegVal readMiscReg(int misc_reg) = 0; 2922159SN/A 29313582Sgabeblack@google.com virtual void setMiscRegNoEffect(int misc_reg, RegVal val) = 0; 2942190SN/A 29513582Sgabeblack@google.com virtual void setMiscReg(int misc_reg, RegVal val) = 0; 2962190SN/A 29712106SRekai.GonzalezAlberquilla@arm.com virtual RegId flattenRegId(const RegId& regId) const = 0; 2986313Sgblack@eecs.umich.edu 29913557Sgabeblack@google.com virtual RegVal 30012106SRekai.GonzalezAlberquilla@arm.com readRegOtherThread(const RegId& misc_reg, ThreadID tid) 3016221Snate@binkert.org { 3026221Snate@binkert.org return 0; 3036221Snate@binkert.org } 3044661Sksewell@umich.edu 3056221Snate@binkert.org virtual void 30613582Sgabeblack@google.com setRegOtherThread(const RegId& misc_reg, RegVal val, ThreadID tid) 3076221Snate@binkert.org { 3086221Snate@binkert.org } 3094661Sksewell@umich.edu 3102235SN/A // Also not necessarily the best location for these two. Hopefully will go 3112235SN/A // away once we decide upon where st cond failures goes. 3122190SN/A virtual unsigned readStCondFailures() = 0; 3132190SN/A 3142190SN/A virtual void setStCondFailures(unsigned sc_failures) = 0; 3152159SN/A 3162235SN/A // Same with st cond failures. 3172190SN/A virtual Counter readFuncExeInst() = 0; 3182834Sksewell@umich.edu 31911877Sbrandon.potter@amd.com virtual void syscall(int64_t callnum, Fault *fault) = 0; 3204111Sgblack@eecs.umich.edu 3212834Sksewell@umich.edu // This function exits the thread context in the CPU and returns 3222834Sksewell@umich.edu // 1 if the CPU has no more active threads (meaning it's OK to exit); 3232834Sksewell@umich.edu // Used in syscall-emulation mode when a thread calls the exit syscall. 3242834Sksewell@umich.edu virtual int exit() { return 1; }; 3252525SN/A 3265217Ssaidi@eecs.umich.edu /** function to compare two thread contexts (for debugging) */ 3275217Ssaidi@eecs.umich.edu static void compare(ThreadContext *one, ThreadContext *two); 3289426SAndreas.Sandberg@ARM.com 3299426SAndreas.Sandberg@ARM.com /** @{ */ 3309426SAndreas.Sandberg@ARM.com /** 3319426SAndreas.Sandberg@ARM.com * Flat register interfaces 3329426SAndreas.Sandberg@ARM.com * 3339426SAndreas.Sandberg@ARM.com * Some architectures have different registers visible in 3349426SAndreas.Sandberg@ARM.com * different modes. Such architectures "flatten" a register (see 33512106SRekai.GonzalezAlberquilla@arm.com * flattenRegId()) to map it into the 3369426SAndreas.Sandberg@ARM.com * gem5 register file. This interface provides a flat interface to 3379426SAndreas.Sandberg@ARM.com * the underlying register file, which allows for example 3389426SAndreas.Sandberg@ARM.com * serialization code to access all registers. 3399426SAndreas.Sandberg@ARM.com */ 3409426SAndreas.Sandberg@ARM.com 34113557Sgabeblack@google.com virtual RegVal readIntRegFlat(int idx) = 0; 34213557Sgabeblack@google.com virtual void setIntRegFlat(int idx, RegVal val) = 0; 3439426SAndreas.Sandberg@ARM.com 34413611Sgabeblack@google.com virtual RegVal readFloatRegFlat(int idx) = 0; 34513611Sgabeblack@google.com virtual void setFloatRegFlat(int idx, RegVal val) = 0; 3469426SAndreas.Sandberg@ARM.com 34712109SRekai.GonzalezAlberquilla@arm.com virtual const VecRegContainer& readVecRegFlat(int idx) const = 0; 34812109SRekai.GonzalezAlberquilla@arm.com virtual VecRegContainer& getWritableVecRegFlat(int idx) = 0; 34912109SRekai.GonzalezAlberquilla@arm.com virtual void setVecRegFlat(int idx, const VecRegContainer& val) = 0; 35012109SRekai.GonzalezAlberquilla@arm.com 35112109SRekai.GonzalezAlberquilla@arm.com virtual const VecElem& readVecElemFlat(const RegIndex& idx, 35212109SRekai.GonzalezAlberquilla@arm.com const ElemIndex& elemIdx) const = 0; 35312109SRekai.GonzalezAlberquilla@arm.com virtual void setVecElemFlat(const RegIndex& idx, const ElemIndex& elemIdx, 35412109SRekai.GonzalezAlberquilla@arm.com const VecElem& val) = 0; 35512109SRekai.GonzalezAlberquilla@arm.com 35613610Sgiacomo.gabrielli@arm.com virtual const VecPredRegContainer& readVecPredRegFlat(int idx) const = 0; 35713610Sgiacomo.gabrielli@arm.com virtual VecPredRegContainer& getWritableVecPredRegFlat(int idx) = 0; 35813610Sgiacomo.gabrielli@arm.com virtual void setVecPredRegFlat(int idx, 35913610Sgiacomo.gabrielli@arm.com const VecPredRegContainer& val) = 0; 36013610Sgiacomo.gabrielli@arm.com 36113622Sgabeblack@google.com virtual RegVal readCCRegFlat(int idx) = 0; 36213622Sgabeblack@google.com virtual void setCCRegFlat(int idx, RegVal val) = 0; 3639426SAndreas.Sandberg@ARM.com /** @} */ 3649426SAndreas.Sandberg@ARM.com 3652159SN/A}; 3662159SN/A 3672682Sktlim@umich.edu/** 3682682Sktlim@umich.edu * ProxyThreadContext class that provides a way to implement a 3692682Sktlim@umich.edu * ThreadContext without having to derive from it. ThreadContext is an 3702682Sktlim@umich.edu * abstract class, so anything that derives from it and uses its 3712682Sktlim@umich.edu * interface will pay the overhead of virtual function calls. This 3722682Sktlim@umich.edu * class is created to enable a user-defined Thread object to be used 3732682Sktlim@umich.edu * wherever ThreadContexts are used, without paying the overhead of 3742682Sktlim@umich.edu * virtual function calls when it is used by itself. See 3752682Sktlim@umich.edu * simple_thread.hh for an example of this. 3762682Sktlim@umich.edu */ 3772680Sktlim@umich.edutemplate <class TC> 3782680Sktlim@umich.educlass ProxyThreadContext : public ThreadContext 3792190SN/A{ 3802190SN/A public: 3812680Sktlim@umich.edu ProxyThreadContext(TC *actual_tc) 3822680Sktlim@umich.edu { actualTC = actual_tc; } 3832159SN/A 3842190SN/A private: 3852680Sktlim@umich.edu TC *actualTC; 3862SN/A 3872SN/A public: 3882SN/A 3892680Sktlim@umich.edu BaseCPU *getCpuPtr() { return actualTC->getCpuPtr(); } 3902SN/A 39110110Sandreas.hansson@arm.com int cpuId() const { return actualTC->cpuId(); } 3922SN/A 39310190Sakash.bagdia@arm.com uint32_t socketId() const { return actualTC->socketId(); } 39410190Sakash.bagdia@arm.com 39510110Sandreas.hansson@arm.com int threadId() const { return actualTC->threadId(); } 3965715Shsul@eecs.umich.edu 39710110Sandreas.hansson@arm.com void setThreadId(int id) { actualTC->setThreadId(id); } 3985714Shsul@eecs.umich.edu 39910110Sandreas.hansson@arm.com int contextId() const { return actualTC->contextId(); } 4005714Shsul@eecs.umich.edu 4015714Shsul@eecs.umich.edu void setContextId(int id) { actualTC->setContextId(id); } 4025714Shsul@eecs.umich.edu 40312406Sgabeblack@google.com BaseTLB *getITBPtr() { return actualTC->getITBPtr(); } 4041917SN/A 40512406Sgabeblack@google.com BaseTLB *getDTBPtr() { return actualTC->getDTBPtr(); } 4062521SN/A 4078887Sgeoffrey.blake@arm.com CheckerCPU *getCheckerCpuPtr() { return actualTC->getCheckerCpuPtr(); } 4088733Sgeoffrey.blake@arm.com 4099020Sgblack@eecs.umich.edu TheISA::Decoder *getDecoderPtr() { return actualTC->getDecoderPtr(); } 4108541Sgblack@eecs.umich.edu 4114997Sgblack@eecs.umich.edu System *getSystemPtr() { return actualTC->getSystemPtr(); } 4124997Sgblack@eecs.umich.edu 4133548Sgblack@eecs.umich.edu TheISA::Kernel::Statistics *getKernelStats() 4143548Sgblack@eecs.umich.edu { return actualTC->getKernelStats(); } 4152654SN/A 4168852Sandreas.hansson@arm.com PortProxy &getPhysProxy() { return actualTC->getPhysProxy(); } 4172521SN/A 4188852Sandreas.hansson@arm.com FSTranslatingPortProxy &getVirtProxy() { return actualTC->getVirtProxy(); } 4193673Srdreslin@umich.edu 4208706Sandreas.hansson@arm.com void initMemProxies(ThreadContext *tc) { actualTC->initMemProxies(tc); } 4218799Sgblack@eecs.umich.edu 4228852Sandreas.hansson@arm.com SETranslatingPortProxy &getMemProxy() { return actualTC->getMemProxy(); } 4232518SN/A 4242680Sktlim@umich.edu Process *getProcessPtr() { return actualTC->getProcessPtr(); } 4252SN/A 42611886Sbrandon.potter@amd.com void setProcessPtr(Process *p) { actualTC->setProcessPtr(p); } 42711886Sbrandon.potter@amd.com 4282680Sktlim@umich.edu Status status() const { return actualTC->status(); } 429595SN/A 4302680Sktlim@umich.edu void setStatus(Status new_status) { actualTC->setStatus(new_status); } 4312SN/A 43210407Smitch.hayenga@arm.com /// Set the status to Active. 43310407Smitch.hayenga@arm.com void activate() { actualTC->activate(); } 4342SN/A 4352190SN/A /// Set the status to Suspended. 43610407Smitch.hayenga@arm.com void suspend() { actualTC->suspend(); } 4372SN/A 4382190SN/A /// Set the status to Halted. 43910407Smitch.hayenga@arm.com void halt() { actualTC->halt(); } 440217SN/A 44111627Smichael.lebeane@amd.com /// Quiesce thread context 44211627Smichael.lebeane@amd.com void quiesce() { actualTC->quiesce(); } 44311627Smichael.lebeane@amd.com 44411627Smichael.lebeane@amd.com /// Quiesce, suspend, and schedule activate at resume 44511627Smichael.lebeane@amd.com void quiesceTick(Tick resume) { actualTC->quiesceTick(resume); } 44611627Smichael.lebeane@amd.com 4472680Sktlim@umich.edu void dumpFuncProfile() { actualTC->dumpFuncProfile(); } 4482190SN/A 4492680Sktlim@umich.edu void takeOverFrom(ThreadContext *oldContext) 4502680Sktlim@umich.edu { actualTC->takeOverFrom(oldContext); } 4512190SN/A 4522680Sktlim@umich.edu void regStats(const std::string &name) { actualTC->regStats(name); } 4532190SN/A 4542680Sktlim@umich.edu EndQuiesceEvent *getQuiesceEvent() { return actualTC->getQuiesceEvent(); } 4552235SN/A 4562680Sktlim@umich.edu Tick readLastActivate() { return actualTC->readLastActivate(); } 4572680Sktlim@umich.edu Tick readLastSuspend() { return actualTC->readLastSuspend(); } 4582254SN/A 4592680Sktlim@umich.edu void profileClear() { return actualTC->profileClear(); } 4602680Sktlim@umich.edu void profileSample() { return actualTC->profileSample(); } 4612SN/A 4622190SN/A // @todo: Do I need this? 4632680Sktlim@umich.edu void copyArchRegs(ThreadContext *tc) { actualTC->copyArchRegs(tc); } 4642SN/A 4652680Sktlim@umich.edu void clearArchRegs() { actualTC->clearArchRegs(); } 466716SN/A 4672SN/A // 4682SN/A // New accessors for new decoder. 4692SN/A // 47013557Sgabeblack@google.com RegVal readIntReg(int reg_idx) 4712680Sktlim@umich.edu { return actualTC->readIntReg(reg_idx); } 4722SN/A 47313611Sgabeblack@google.com RegVal readFloatReg(int reg_idx) 47413611Sgabeblack@google.com { return actualTC->readFloatReg(reg_idx); } 4752SN/A 47612109SRekai.GonzalezAlberquilla@arm.com const VecRegContainer& readVecReg(const RegId& reg) const 47712109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVecReg(reg); } 47812109SRekai.GonzalezAlberquilla@arm.com 47912109SRekai.GonzalezAlberquilla@arm.com VecRegContainer& getWritableVecReg(const RegId& reg) 48012109SRekai.GonzalezAlberquilla@arm.com { return actualTC->getWritableVecReg(reg); } 48112109SRekai.GonzalezAlberquilla@arm.com 48212109SRekai.GonzalezAlberquilla@arm.com /** Vector Register Lane Interfaces. */ 48312109SRekai.GonzalezAlberquilla@arm.com /** @{ */ 48412109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 8bit operand. */ 48512109SRekai.GonzalezAlberquilla@arm.com ConstVecLane8 48612109SRekai.GonzalezAlberquilla@arm.com readVec8BitLaneReg(const RegId& reg) const 48712109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVec8BitLaneReg(reg); } 48812109SRekai.GonzalezAlberquilla@arm.com 48912109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 16bit operand. */ 49012109SRekai.GonzalezAlberquilla@arm.com ConstVecLane16 49112109SRekai.GonzalezAlberquilla@arm.com readVec16BitLaneReg(const RegId& reg) const 49212109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVec16BitLaneReg(reg); } 49312109SRekai.GonzalezAlberquilla@arm.com 49412109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 32bit operand. */ 49512109SRekai.GonzalezAlberquilla@arm.com ConstVecLane32 49612109SRekai.GonzalezAlberquilla@arm.com readVec32BitLaneReg(const RegId& reg) const 49712109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVec32BitLaneReg(reg); } 49812109SRekai.GonzalezAlberquilla@arm.com 49912109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 64bit operand. */ 50012109SRekai.GonzalezAlberquilla@arm.com ConstVecLane64 50112109SRekai.GonzalezAlberquilla@arm.com readVec64BitLaneReg(const RegId& reg) const 50212109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVec64BitLaneReg(reg); } 50312109SRekai.GonzalezAlberquilla@arm.com 50412109SRekai.GonzalezAlberquilla@arm.com /** Write a lane of the destination vector register. */ 50512109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 50612109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::Byte>& val) 50712109SRekai.GonzalezAlberquilla@arm.com { return actualTC->setVecLane(reg, val); } 50812109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 50912109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::TwoByte>& val) 51012109SRekai.GonzalezAlberquilla@arm.com { return actualTC->setVecLane(reg, val); } 51112109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 51212109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::FourByte>& val) 51312109SRekai.GonzalezAlberquilla@arm.com { return actualTC->setVecLane(reg, val); } 51412109SRekai.GonzalezAlberquilla@arm.com virtual void setVecLane(const RegId& reg, 51512109SRekai.GonzalezAlberquilla@arm.com const LaneData<LaneSize::EightByte>& val) 51612109SRekai.GonzalezAlberquilla@arm.com { return actualTC->setVecLane(reg, val); } 51712109SRekai.GonzalezAlberquilla@arm.com /** @} */ 51812109SRekai.GonzalezAlberquilla@arm.com 51912109SRekai.GonzalezAlberquilla@arm.com const VecElem& readVecElem(const RegId& reg) const 52012109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVecElem(reg); } 52112109SRekai.GonzalezAlberquilla@arm.com 52213610Sgiacomo.gabrielli@arm.com const VecPredRegContainer& readVecPredReg(const RegId& reg) const 52313610Sgiacomo.gabrielli@arm.com { return actualTC->readVecPredReg(reg); } 52413610Sgiacomo.gabrielli@arm.com 52513610Sgiacomo.gabrielli@arm.com VecPredRegContainer& getWritableVecPredReg(const RegId& reg) 52613610Sgiacomo.gabrielli@arm.com { return actualTC->getWritableVecPredReg(reg); } 52713610Sgiacomo.gabrielli@arm.com 52813622Sgabeblack@google.com RegVal readCCReg(int reg_idx) 5299920Syasuko.eckert@amd.com { return actualTC->readCCReg(reg_idx); } 5309920Syasuko.eckert@amd.com 53113557Sgabeblack@google.com void setIntReg(int reg_idx, RegVal val) 5322680Sktlim@umich.edu { actualTC->setIntReg(reg_idx, val); } 5332SN/A 53413611Sgabeblack@google.com void setFloatReg(int reg_idx, RegVal val) 53513611Sgabeblack@google.com { actualTC->setFloatReg(reg_idx, val); } 5362SN/A 53712109SRekai.GonzalezAlberquilla@arm.com void setVecReg(const RegId& reg, const VecRegContainer& val) 53812109SRekai.GonzalezAlberquilla@arm.com { actualTC->setVecReg(reg, val); } 53912109SRekai.GonzalezAlberquilla@arm.com 54013610Sgiacomo.gabrielli@arm.com void setVecPredReg(const RegId& reg, const VecPredRegContainer& val) 54113610Sgiacomo.gabrielli@arm.com { actualTC->setVecPredReg(reg, val); } 54213610Sgiacomo.gabrielli@arm.com 54312109SRekai.GonzalezAlberquilla@arm.com void setVecElem(const RegId& reg, const VecElem& val) 54412109SRekai.GonzalezAlberquilla@arm.com { actualTC->setVecElem(reg, val); } 54512109SRekai.GonzalezAlberquilla@arm.com 54613622Sgabeblack@google.com void setCCReg(int reg_idx, RegVal val) 5479920Syasuko.eckert@amd.com { actualTC->setCCReg(reg_idx, val); } 5489920Syasuko.eckert@amd.com 5497720Sgblack@eecs.umich.edu TheISA::PCState pcState() { return actualTC->pcState(); } 5502SN/A 5517720Sgblack@eecs.umich.edu void pcState(const TheISA::PCState &val) { actualTC->pcState(val); } 5522206SN/A 5538733Sgeoffrey.blake@arm.com void pcStateNoRecord(const TheISA::PCState &val) { actualTC->pcState(val); } 5548733Sgeoffrey.blake@arm.com 5557720Sgblack@eecs.umich.edu Addr instAddr() { return actualTC->instAddr(); } 5567720Sgblack@eecs.umich.edu Addr nextInstAddr() { return actualTC->nextInstAddr(); } 5577720Sgblack@eecs.umich.edu MicroPC microPC() { return actualTC->microPC(); } 5585260Sksewell@umich.edu 5597597Sminkyu.jeong@arm.com bool readPredicate() { return actualTC->readPredicate(); } 5607597Sminkyu.jeong@arm.com 5617597Sminkyu.jeong@arm.com void setPredicate(bool val) 5627597Sminkyu.jeong@arm.com { actualTC->setPredicate(val); } 5637597Sminkyu.jeong@arm.com 56413557Sgabeblack@google.com RegVal readMiscRegNoEffect(int misc_reg) const 5654172Ssaidi@eecs.umich.edu { return actualTC->readMiscRegNoEffect(misc_reg); } 5664172Ssaidi@eecs.umich.edu 56713557Sgabeblack@google.com RegVal readMiscReg(int misc_reg) 5682680Sktlim@umich.edu { return actualTC->readMiscReg(misc_reg); } 5692SN/A 57013582Sgabeblack@google.com void setMiscRegNoEffect(int misc_reg, RegVal val) 5714172Ssaidi@eecs.umich.edu { return actualTC->setMiscRegNoEffect(misc_reg, val); } 5722SN/A 57313582Sgabeblack@google.com void setMiscReg(int misc_reg, RegVal val) 5742680Sktlim@umich.edu { return actualTC->setMiscReg(misc_reg, val); } 5752SN/A 57612106SRekai.GonzalezAlberquilla@arm.com RegId flattenRegId(const RegId& regId) const 57712106SRekai.GonzalezAlberquilla@arm.com { return actualTC->flattenRegId(regId); } 57810033SAli.Saidi@ARM.com 5792190SN/A unsigned readStCondFailures() 5802680Sktlim@umich.edu { return actualTC->readStCondFailures(); } 5812190SN/A 5822190SN/A void setStCondFailures(unsigned sc_failures) 5832680Sktlim@umich.edu { actualTC->setStCondFailures(sc_failures); } 5842SN/A 58511877Sbrandon.potter@amd.com void syscall(int64_t callnum, Fault *fault) 58611877Sbrandon.potter@amd.com { actualTC->syscall(callnum, fault); } 5874111Sgblack@eecs.umich.edu 5882680Sktlim@umich.edu Counter readFuncExeInst() { return actualTC->readFuncExeInst(); } 5899426SAndreas.Sandberg@ARM.com 59013557Sgabeblack@google.com RegVal readIntRegFlat(int idx) 5919426SAndreas.Sandberg@ARM.com { return actualTC->readIntRegFlat(idx); } 5929426SAndreas.Sandberg@ARM.com 59313557Sgabeblack@google.com void setIntRegFlat(int idx, RegVal val) 5949426SAndreas.Sandberg@ARM.com { actualTC->setIntRegFlat(idx, val); } 5959426SAndreas.Sandberg@ARM.com 59613611Sgabeblack@google.com RegVal readFloatRegFlat(int idx) 59713611Sgabeblack@google.com { return actualTC->readFloatRegFlat(idx); } 5989426SAndreas.Sandberg@ARM.com 59913611Sgabeblack@google.com void setFloatRegFlat(int idx, RegVal val) 60013611Sgabeblack@google.com { actualTC->setFloatRegFlat(idx, val); } 6019920Syasuko.eckert@amd.com 60212109SRekai.GonzalezAlberquilla@arm.com const VecRegContainer& readVecRegFlat(int id) const 60312109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVecRegFlat(id); } 60412109SRekai.GonzalezAlberquilla@arm.com 60512109SRekai.GonzalezAlberquilla@arm.com VecRegContainer& getWritableVecRegFlat(int id) 60612109SRekai.GonzalezAlberquilla@arm.com { return actualTC->getWritableVecRegFlat(id); } 60712109SRekai.GonzalezAlberquilla@arm.com 60812109SRekai.GonzalezAlberquilla@arm.com void setVecRegFlat(int idx, const VecRegContainer& val) 60912109SRekai.GonzalezAlberquilla@arm.com { actualTC->setVecRegFlat(idx, val); } 61012109SRekai.GonzalezAlberquilla@arm.com 61112109SRekai.GonzalezAlberquilla@arm.com const VecElem& readVecElemFlat(const RegIndex& id, 61212109SRekai.GonzalezAlberquilla@arm.com const ElemIndex& elemIndex) const 61312109SRekai.GonzalezAlberquilla@arm.com { return actualTC->readVecElemFlat(id, elemIndex); } 61412109SRekai.GonzalezAlberquilla@arm.com 61512109SRekai.GonzalezAlberquilla@arm.com void setVecElemFlat(const RegIndex& id, const ElemIndex& elemIndex, 61612109SRekai.GonzalezAlberquilla@arm.com const VecElem& val) 61712109SRekai.GonzalezAlberquilla@arm.com { actualTC->setVecElemFlat(id, elemIndex, val); } 61812109SRekai.GonzalezAlberquilla@arm.com 61913610Sgiacomo.gabrielli@arm.com const VecPredRegContainer& readVecPredRegFlat(int id) const 62013610Sgiacomo.gabrielli@arm.com { return actualTC->readVecPredRegFlat(id); } 62113610Sgiacomo.gabrielli@arm.com 62213610Sgiacomo.gabrielli@arm.com VecPredRegContainer& getWritableVecPredRegFlat(int id) 62313610Sgiacomo.gabrielli@arm.com { return actualTC->getWritableVecPredRegFlat(id); } 62413610Sgiacomo.gabrielli@arm.com 62513610Sgiacomo.gabrielli@arm.com void setVecPredRegFlat(int idx, const VecPredRegContainer& val) 62613610Sgiacomo.gabrielli@arm.com { actualTC->setVecPredRegFlat(idx, val); } 62713610Sgiacomo.gabrielli@arm.com 62813622Sgabeblack@google.com RegVal readCCRegFlat(int idx) 6299920Syasuko.eckert@amd.com { return actualTC->readCCRegFlat(idx); } 6309920Syasuko.eckert@amd.com 63113622Sgabeblack@google.com void setCCRegFlat(int idx, RegVal val) 6329920Syasuko.eckert@amd.com { actualTC->setCCRegFlat(idx, val); } 6332SN/A}; 6342SN/A 6359428SAndreas.Sandberg@ARM.com/** @{ */ 6369428SAndreas.Sandberg@ARM.com/** 6379428SAndreas.Sandberg@ARM.com * Thread context serialization helpers 6389428SAndreas.Sandberg@ARM.com * 6399428SAndreas.Sandberg@ARM.com * These helper functions provide a way to the data in a 6409428SAndreas.Sandberg@ARM.com * ThreadContext. They are provided as separate helper function since 6419428SAndreas.Sandberg@ARM.com * implementing them as members of the ThreadContext interface would 6429428SAndreas.Sandberg@ARM.com * be confusing when the ThreadContext is exported via a proxy. 6439428SAndreas.Sandberg@ARM.com */ 6449428SAndreas.Sandberg@ARM.com 64510905Sandreas.sandberg@arm.comvoid serialize(ThreadContext &tc, CheckpointOut &cp); 64610905Sandreas.sandberg@arm.comvoid unserialize(ThreadContext &tc, CheckpointIn &cp); 6479428SAndreas.Sandberg@ARM.com 6489428SAndreas.Sandberg@ARM.com/** @} */ 6499428SAndreas.Sandberg@ARM.com 6509441SAndreas.Sandberg@ARM.com 6519441SAndreas.Sandberg@ARM.com/** 6529441SAndreas.Sandberg@ARM.com * Copy state between thread contexts in preparation for CPU handover. 6539441SAndreas.Sandberg@ARM.com * 6549441SAndreas.Sandberg@ARM.com * @note This method modifies the old thread contexts as well as the 6559441SAndreas.Sandberg@ARM.com * new thread context. The old thread context will have its quiesce 6569441SAndreas.Sandberg@ARM.com * event descheduled if it is scheduled and its status set to halted. 6579441SAndreas.Sandberg@ARM.com * 6589441SAndreas.Sandberg@ARM.com * @param new_tc Destination ThreadContext. 6599441SAndreas.Sandberg@ARM.com * @param old_tc Source ThreadContext. 6609441SAndreas.Sandberg@ARM.com */ 6619441SAndreas.Sandberg@ARM.comvoid takeOverFrom(ThreadContext &new_tc, ThreadContext &old_tc); 6629441SAndreas.Sandberg@ARM.com 6632190SN/A#endif 664