thread_context.hh revision 11627
12292SN/A/* 29444SAndreas.Sandberg@ARM.com * Copyright (c) 2011-2012 ARM Limited 39444SAndreas.Sandberg@ARM.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 49444SAndreas.Sandberg@ARM.com * All rights reserved 59444SAndreas.Sandberg@ARM.com * 69444SAndreas.Sandberg@ARM.com * The license below extends only to copyright in the software and shall 79444SAndreas.Sandberg@ARM.com * not be construed as granting a license to any other intellectual 89444SAndreas.Sandberg@ARM.com * property including but not limited to intellectual property relating 99444SAndreas.Sandberg@ARM.com * to a hardware implementation of the functionality of the software 109444SAndreas.Sandberg@ARM.com * licensed hereunder. You may use the software subject to the license 119444SAndreas.Sandberg@ARM.com * terms below provided that you ensure that this notice is replicated 129444SAndreas.Sandberg@ARM.com * unmodified and in its entirety in all distributions of the software, 139444SAndreas.Sandberg@ARM.com * modified or unmodified, in source code or in binary form. 142329SN/A * 152292SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 162292SN/A * All rights reserved. 172292SN/A * 182292SN/A * Redistribution and use in source and binary forms, with or without 192292SN/A * modification, are permitted provided that the following conditions are 202292SN/A * met: redistributions of source code must retain the above copyright 212292SN/A * notice, this list of conditions and the following disclaimer; 222292SN/A * redistributions in binary form must reproduce the above copyright 232292SN/A * notice, this list of conditions and the following disclaimer in the 242292SN/A * documentation and/or other materials provided with the distribution; 252292SN/A * neither the name of the copyright holders nor the names of its 262292SN/A * contributors may be used to endorse or promote products derived from 272292SN/A * this software without specific prior written permission. 282292SN/A * 292292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392689Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402689Sktlim@umich.edu * 412689Sktlim@umich.edu * Authors: Kevin Lim 422292SN/A */ 432292SN/A 442292SN/A#ifndef __CPU_O3_THREAD_CONTEXT_HH__ 452292SN/A#define __CPU_O3_THREAD_CONTEXT_HH__ 462292SN/A 472329SN/A#include "config/the_isa.hh" 484395Ssaidi@eecs.umich.edu#include "cpu/o3/isa_specific.hh" 492292SN/A#include "cpu/thread_context.hh" 502292SN/A 512292SN/Aclass EndQuiesceEvent; 528591Sgblack@eecs.umich.edunamespace Kernel { 538506Sgblack@eecs.umich.edu class Statistics; 543326Sktlim@umich.edu} 558481Sgblack@eecs.umich.edu 568229Snate@binkert.org/** 576658Snate@binkert.org * Derived ThreadContext class for use with the O3CPU. It 582292SN/A * provides the interface for any external objects to access a 598230Snate@binkert.org * single thread's state and some general CPU state. Any time 608232Snate@binkert.org * external objects try to update state through this interface, 613348Sbinkertn@umich.edu * the CPU will create an event to squash all in-flight 622669Sktlim@umich.edu * instructions in order to ensure state is maintained correctly. 638817Sgblack@eecs.umich.edu * It must be defined specifically for the O3CPU because 642292SN/A * not all architectural state is located within the O3ThreadState 658737Skoansin.tan@gmail.com * (such as the commit PC, and registers), and specific actions 665529Snate@binkert.org * must be taken when using this interface (such as squashing all 672292SN/A * in-flight instructions when doing a write to this interface). 682329SN/A */ 692329SN/Atemplate <class Impl> 702329SN/Aclass O3ThreadContext : public ThreadContext 712329SN/A{ 722329SN/A public: 732329SN/A typedef typename Impl::O3CPU O3CPU; 742329SN/A 752329SN/A /** Pointer to the CPU. */ 762329SN/A O3CPU *cpu; 772329SN/A 782292SN/A /** Pointer to the thread state that this TC corrseponds to. */ 792292SN/A O3ThreadState<Impl> *thread; 802292SN/A 812292SN/A /** Returns a pointer to the ITB. */ 822733Sktlim@umich.edu TheISA::TLB *getITBPtr() { return cpu->itb; } 832292SN/A 842292SN/A /** Returns a pointer to the DTB. */ 852907Sktlim@umich.edu TheISA::TLB *getDTBPtr() { return cpu->dtb; } 862292SN/A 872292SN/A CheckerCPU *getCheckerCpuPtr() { return NULL; } 882292SN/A 892292SN/A TheISA::Decoder * 902292SN/A getDecoderPtr() 912292SN/A { 922292SN/A return cpu->fetch.decoder[thread->threadId()]; 935529Snate@binkert.org } 945529Snate@binkert.org 955529Snate@binkert.org /** Returns a pointer to this CPU. */ 962292SN/A virtual BaseCPU *getCpuPtr() { return cpu; } 972292SN/A 982292SN/A /** Reads this CPU's ID. */ 992292SN/A virtual int cpuId() const { return cpu->cpuId(); } 1002727Sktlim@umich.edu 1012727Sktlim@umich.edu /** Reads this CPU's Socket ID. */ 1022727Sktlim@umich.edu virtual uint32_t socketId() const { return cpu->socketId(); } 1032907Sktlim@umich.edu 1048922Swilliam.wang@arm.com virtual ContextID contextId() const { return thread->contextId(); } 1052907Sktlim@umich.edu 1069444SAndreas.Sandberg@ARM.com virtual void setContextId(int id) { thread->setContextId(id); } 1079444SAndreas.Sandberg@ARM.com 1082307SN/A /** Returns this thread's ID number. */ 1092348SN/A virtual int threadId() const { return thread->threadId(); } 1102307SN/A virtual void setThreadId(int id) { return thread->setThreadId(id); } 1112307SN/A 1122292SN/A /** Returns a pointer to the system. */ 1132292SN/A virtual System *getSystemPtr() { return cpu->system; } 1142292SN/A 1152292SN/A /** Returns a pointer to this thread's kernel statistics. */ 1162292SN/A virtual TheISA::Kernel::Statistics *getKernelStats() 1172292SN/A { return thread->kernelStats; } 1182292SN/A 1192292SN/A /** Returns a pointer to this thread's process. */ 1202292SN/A virtual Process *getProcessPtr() { return thread->getProcessPtr(); } 1212292SN/A 1222292SN/A virtual PortProxy &getPhysProxy() { return thread->getPhysProxy(); } 1232292SN/A 1242292SN/A virtual FSTranslatingPortProxy &getVirtProxy(); 1252292SN/A 1268545Ssaidi@eecs.umich.edu virtual void initMemProxies(ThreadContext *tc) 1278545Ssaidi@eecs.umich.edu { thread->initMemProxies(tc); } 1288545Ssaidi@eecs.umich.edu 1298199SAli.Saidi@ARM.com virtual SETranslatingPortProxy &getMemProxy() 1308199SAli.Saidi@ARM.com { return thread->getMemProxy(); } 1318199SAli.Saidi@ARM.com 1328199SAli.Saidi@ARM.com /** Returns this thread's status. */ 1338199SAli.Saidi@ARM.com virtual Status status() const { return thread->status(); } 1348545Ssaidi@eecs.umich.edu 1358545Ssaidi@eecs.umich.edu /** Sets this thread's status. */ 1368545Ssaidi@eecs.umich.edu virtual void setStatus(Status new_status) 1378545Ssaidi@eecs.umich.edu { thread->setStatus(new_status); } 1388545Ssaidi@eecs.umich.edu 1398545Ssaidi@eecs.umich.edu /** Set the status to Active. */ 1402292SN/A virtual void activate(); 1412292SN/A 1422292SN/A /** Set the status to Suspended. */ 1432329SN/A virtual void suspend(); 1442292SN/A 1452292SN/A /** Set the status to Halted. */ 1462292SN/A virtual void halt(); 1472292SN/A 1482292SN/A /** Dumps the function profiling information. 1492292SN/A * @todo: Implement. 1502292SN/A */ 1512292SN/A virtual void dumpFuncProfile(); 1522292SN/A 1532292SN/A /** Takes over execution of a thread from another CPU. */ 1542292SN/A virtual void takeOverFrom(ThreadContext *old_context); 1552292SN/A 1562292SN/A /** Registers statistics associated with this TC. */ 1572292SN/A virtual void regStats(const std::string &name); 1582790Sktlim@umich.edu 1592790Sktlim@umich.edu /** Reads the last tick that this thread was activated on. */ 1602669Sktlim@umich.edu virtual Tick readLastActivate(); 1612669Sktlim@umich.edu /** Reads the last tick that this thread was suspended on. */ 1622292SN/A virtual Tick readLastSuspend(); 1632292SN/A 1642292SN/A /** Clears the function profiling information. */ 1652292SN/A virtual void profileClear(); 1662292SN/A /** Samples the function profiling information. */ 1672292SN/A virtual void profileSample(); 1682292SN/A 1692292SN/A /** Copies the architectural registers from another TC into this TC. */ 1702292SN/A virtual void copyArchRegs(ThreadContext *tc); 1712292SN/A 1722292SN/A /** Resets all architectural registers to 0. */ 1732292SN/A virtual void clearArchRegs(); 1742292SN/A 1752292SN/A /** Reads an integer register. */ 1762292SN/A virtual uint64_t readIntReg(int reg_idx) { 1772292SN/A return readIntRegFlat(flattenIntIndex(reg_idx)); 1782292SN/A } 1792292SN/A 1802292SN/A virtual FloatReg readFloatReg(int reg_idx) { 1812292SN/A return readFloatRegFlat(flattenFloatIndex(reg_idx)); 1822292SN/A } 1832292SN/A 1842292SN/A virtual FloatRegBits readFloatRegBits(int reg_idx) { 1852329SN/A return readFloatRegBitsFlat(flattenFloatIndex(reg_idx)); 1862292SN/A } 1872292SN/A 1882292SN/A virtual CCReg readCCReg(int reg_idx) { 1892348SN/A return readCCRegFlat(flattenCCIndex(reg_idx)); 1902292SN/A } 1912292SN/A 1922292SN/A /** Sets an integer register to a value. */ 1932348SN/A virtual void setIntReg(int reg_idx, uint64_t val) { 1942292SN/A setIntRegFlat(flattenIntIndex(reg_idx), val); 1952292SN/A } 1962292SN/A 1972348SN/A virtual void setFloatReg(int reg_idx, FloatReg val) { 1982292SN/A setFloatRegFlat(flattenFloatIndex(reg_idx), val); 1992292SN/A } 2002292SN/A 2012292SN/A virtual void setFloatRegBits(int reg_idx, FloatRegBits val) { 2022292SN/A setFloatRegBitsFlat(flattenFloatIndex(reg_idx), val); 2032292SN/A } 2042292SN/A 2052292SN/A virtual void setCCReg(int reg_idx, CCReg val) { 2062292SN/A setCCRegFlat(flattenCCIndex(reg_idx), val); 2072292SN/A } 2082292SN/A 2092292SN/A /** Reads this thread's PC state. */ 2102292SN/A virtual TheISA::PCState pcState() 2112292SN/A { return cpu->pcState(thread->threadId()); } 2122292SN/A 2139444SAndreas.Sandberg@ARM.com /** Sets this thread's PC state. */ 2149444SAndreas.Sandberg@ARM.com virtual void pcState(const TheISA::PCState &val); 2159444SAndreas.Sandberg@ARM.com 2162292SN/A virtual void pcStateNoRecord(const TheISA::PCState &val); 2172292SN/A 2182292SN/A /** Reads this thread's PC. */ 2192292SN/A virtual Addr instAddr() 2202292SN/A { return cpu->instAddr(thread->threadId()); } 2212292SN/A 2229444SAndreas.Sandberg@ARM.com /** Reads this thread's next PC. */ 2239444SAndreas.Sandberg@ARM.com virtual Addr nextInstAddr() 2249444SAndreas.Sandberg@ARM.com { return cpu->nextInstAddr(thread->threadId()); } 2259444SAndreas.Sandberg@ARM.com 2269444SAndreas.Sandberg@ARM.com /** Reads this thread's next PC. */ 2279444SAndreas.Sandberg@ARM.com virtual MicroPC microPC() 2282292SN/A { return cpu->microPC(thread->threadId()); } 2292292SN/A 2302292SN/A /** Reads a miscellaneous register. */ 2312292SN/A virtual MiscReg readMiscRegNoEffect(int misc_reg) const 2322292SN/A { return cpu->readMiscRegNoEffect(misc_reg, thread->threadId()); } 2332292SN/A 2342292SN/A /** Reads a misc. register, including any side-effects the 2352292SN/A * read might have as defined by the architecture. */ 2362292SN/A virtual MiscReg readMiscReg(int misc_reg) 2372292SN/A { return cpu->readMiscReg(misc_reg, thread->threadId()); } 2382292SN/A 2392678Sktlim@umich.edu /** Sets a misc. register. */ 2402678Sktlim@umich.edu virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val); 2412292SN/A 2422907Sktlim@umich.edu /** Sets a misc. register, including any side-effects the 2432907Sktlim@umich.edu * write might have as defined by the architecture. */ 2442907Sktlim@umich.edu virtual void setMiscReg(int misc_reg, const MiscReg &val); 2452292SN/A 2469444SAndreas.Sandberg@ARM.com virtual int flattenIntIndex(int reg); 2479444SAndreas.Sandberg@ARM.com virtual int flattenFloatIndex(int reg); 2489444SAndreas.Sandberg@ARM.com virtual int flattenCCIndex(int reg); 2492698Sktlim@umich.edu virtual int flattenMiscIndex(int reg); 2502678Sktlim@umich.edu 2512678Sktlim@umich.edu /** Returns the number of consecutive store conditional failures. */ 2526974Stjones1@inf.ed.ac.uk // @todo: Figure out where these store cond failures should go. 2536974Stjones1@inf.ed.ac.uk virtual unsigned readStCondFailures() 2546974Stjones1@inf.ed.ac.uk { return thread->storeCondFailures; } 2552698Sktlim@umich.edu 2563349Sbinkertn@umich.edu /** Sets the number of consecutive store conditional failures. */ 2572693Sktlim@umich.edu virtual void setStCondFailures(unsigned sc_failures) 2582292SN/A { thread->storeCondFailures = sc_failures; } 2592292SN/A 2602292SN/A /** Executes a syscall in SE mode. */ 2616974Stjones1@inf.ed.ac.uk virtual void syscall(int64_t callnum) 2626974Stjones1@inf.ed.ac.uk { return cpu->syscall(callnum, thread->threadId()); } 2636974Stjones1@inf.ed.ac.uk 2642292SN/A /** Reads the funcExeInst counter. */ 2659440SAndreas.Sandberg@ARM.com virtual Counter readFuncExeInst() { return thread->funcExeInst; } 2662292SN/A 2679440SAndreas.Sandberg@ARM.com /** Returns pointer to the quiesce event. */ 2682292SN/A virtual EndQuiesceEvent *getQuiesceEvent() 2699440SAndreas.Sandberg@ARM.com { 2702292SN/A return this->thread->quiesceEvent; 2719440SAndreas.Sandberg@ARM.com } 2722292SN/A /** check if the cpu is currently in state update mode and squash if not. 2732329SN/A * This function will return true if a trap is pending or if a fault or 2742329SN/A * similar is currently writing to the thread context and doesn't want 2759440SAndreas.Sandberg@ARM.com * reset all the state (see noSquashFromTC). 2762329SN/A */ 2772292SN/A inline void conditionalSquash() 2782292SN/A { 2792733Sktlim@umich.edu if (!thread->trapPending && !thread->noSquashFromTC) 2802292SN/A cpu->squashFromTC(thread->threadId()); 2812292SN/A } 2822292SN/A 2832292SN/A virtual uint64_t readIntRegFlat(int idx); 2842907Sktlim@umich.edu virtual void setIntRegFlat(int idx, uint64_t val); 2852907Sktlim@umich.edu 2862669Sktlim@umich.edu virtual FloatReg readFloatRegFlat(int idx); 2872907Sktlim@umich.edu virtual void setFloatRegFlat(int idx, FloatReg val); 2888922Swilliam.wang@arm.com 2892292SN/A virtual FloatRegBits readFloatRegBitsFlat(int idx); 2902698Sktlim@umich.edu virtual void setFloatRegBitsFlat(int idx, FloatRegBits val); 2919044SAli.Saidi@ARM.com 2922678Sktlim@umich.edu virtual CCReg readCCRegFlat(int idx); 2932678Sktlim@umich.edu virtual void setCCRegFlat(int idx, CCReg val); 2942698Sktlim@umich.edu}; 2952678Sktlim@umich.edu 2969046SAli.Saidi@ARM.com#endif 2979046SAli.Saidi@ARM.com