simple_thread.hh revision 13875
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 * 152188SN/A * Copyright (c) 2001-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: Steve Reinhardt 422665SN/A * Nathan Binkert 432SN/A */ 442SN/A 452683Sktlim@umich.edu#ifndef __CPU_SIMPLE_THREAD_HH__ 462683Sktlim@umich.edu#define __CPU_SIMPLE_THREAD_HH__ 472SN/A 489020Sgblack@eecs.umich.edu#include "arch/decoder.hh" 4912406Sgabeblack@google.com#include "arch/generic/tlb.hh" 506313Sgblack@eecs.umich.edu#include "arch/isa.hh" 512190SN/A#include "arch/isa_traits.hh" 526329Sgblack@eecs.umich.edu#include "arch/registers.hh" 536316Sgblack@eecs.umich.edu#include "arch/types.hh" 546216Snate@binkert.org#include "base/types.hh" 556658Snate@binkert.org#include "config/the_isa.hh" 562680SN/A#include "cpu/thread_context.hh" 572683Sktlim@umich.edu#include "cpu/thread_state.hh" 589920Syasuko.eckert@amd.com#include "debug/CCRegs.hh" 598232Snate@binkert.org#include "debug/FloatRegs.hh" 608232Snate@binkert.org#include "debug/IntRegs.hh" 6113610Sgiacomo.gabrielli@arm.com#include "debug/VecPredRegs.hh" 6212109SRekai.GonzalezAlberquilla@arm.com#include "debug/VecRegs.hh" 638777Sgblack@eecs.umich.edu#include "mem/page_table.hh" 642395SN/A#include "mem/request.hh" 652190SN/A#include "sim/byteswap.hh" 662188SN/A#include "sim/eventq.hh" 678777Sgblack@eecs.umich.edu#include "sim/process.hh" 68217SN/A#include "sim/serialize.hh" 698777Sgblack@eecs.umich.edu#include "sim/system.hh" 702SN/A 712SN/Aclass BaseCPU; 728887Sgeoffrey.blake@arm.comclass CheckerCPU; 731070SN/A 741917SN/Aclass FunctionProfile; 751917SN/Aclass ProfileNode; 762521SN/A 773548Sgblack@eecs.umich.edunamespace TheISA { 783548Sgblack@eecs.umich.edu namespace Kernel { 793548Sgblack@eecs.umich.edu class Statistics; 808902Sandreas.hansson@arm.com } 818902Sandreas.hansson@arm.com} 822330SN/A 832683Sktlim@umich.edu/** 842683Sktlim@umich.edu * The SimpleThread object provides a combination of the ThreadState 852683Sktlim@umich.edu * object and the ThreadContext interface. It implements the 8613865Sgabeblack@google.com * ThreadContext interface and adds to the ThreadState object by adding all 872683Sktlim@umich.edu * the objects needed for simple functional execution, including a 882683Sktlim@umich.edu * simple architectural register file, and pointers to the ITB and DTB 892683Sktlim@umich.edu * in full system mode. For CPU models that do not need more advanced 902683Sktlim@umich.edu * ways to hold state (i.e. a separate physical register file, or 912683Sktlim@umich.edu * separate fetch and commit PC's), this SimpleThread class provides 922683Sktlim@umich.edu * all the necessary state for full architecture-level functional 932683Sktlim@umich.edu * simulation. See the AtomicSimpleCPU or TimingSimpleCPU for 942683Sktlim@umich.edu * examples. 952683Sktlim@umich.edu */ 962SN/A 9713865Sgabeblack@google.comclass SimpleThread : public ThreadState, public ThreadContext 982SN/A{ 992107SN/A protected: 1002107SN/A typedef TheISA::MachInst MachInst; 10112109SRekai.GonzalezAlberquilla@arm.com using VecRegContainer = TheISA::VecRegContainer; 10212109SRekai.GonzalezAlberquilla@arm.com using VecElem = TheISA::VecElem; 10313610Sgiacomo.gabrielli@arm.com using VecPredRegContainer = TheISA::VecPredRegContainer; 1042SN/A public: 1052680SN/A typedef ThreadContext::Status Status; 1062SN/A 1072190SN/A protected: 10813557Sgabeblack@google.com RegVal floatRegs[TheISA::NumFloatRegs]; 10913557Sgabeblack@google.com RegVal intRegs[TheISA::NumIntRegs]; 11012109SRekai.GonzalezAlberquilla@arm.com VecRegContainer vecRegs[TheISA::NumVecRegs]; 11113610Sgiacomo.gabrielli@arm.com VecPredRegContainer vecPredRegs[TheISA::NumVecPredRegs]; 1129920Syasuko.eckert@amd.com#ifdef ISA_HAS_CC_REGS 11313622Sgabeblack@google.com RegVal ccRegs[TheISA::NumCCRegs]; 1149920Syasuko.eckert@amd.com#endif 1159384SAndreas.Sandberg@arm.com TheISA::ISA *const isa; // one "instance" of the current ISA. 1162SN/A 1177720Sgblack@eecs.umich.edu TheISA::PCState _pcState; 1186324Sgblack@eecs.umich.edu 1197597Sminkyu.jeong@arm.com /** Did this instruction execute or is it predicated false */ 1207597Sminkyu.jeong@arm.com bool predicate; 1217597Sminkyu.jeong@arm.com 1222190SN/A public: 1238357Sksewell@umich.edu std::string name() const 1248357Sksewell@umich.edu { 12513865Sgabeblack@google.com return csprintf("%s.[tid:%i]", baseCpu->name(), threadId()); 1268357Sksewell@umich.edu } 1278357Sksewell@umich.edu 1282378SN/A System *system; 1292400SN/A 13012406Sgabeblack@google.com BaseTLB *itb; 13112406Sgabeblack@google.com BaseTLB *dtb; 1322SN/A 1339020Sgblack@eecs.umich.edu TheISA::Decoder decoder; 1348541Sgblack@eecs.umich.edu 1352683Sktlim@umich.edu // constructor: initialize SimpleThread from given process structure 1368793Sgblack@eecs.umich.edu // FS 1372683Sktlim@umich.edu SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, 13812406Sgabeblack@google.com BaseTLB *_itb, BaseTLB *_dtb, TheISA::ISA *_isa, 1392683Sktlim@umich.edu bool use_kernel_stats = true); 1408793Sgblack@eecs.umich.edu // SE 1418820Sgblack@eecs.umich.edu SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, 14212406Sgabeblack@google.com Process *_process, BaseTLB *_itb, BaseTLB *_dtb, 1439384SAndreas.Sandberg@arm.com TheISA::ISA *_isa); 1442862Sktlim@umich.edu 14513865Sgabeblack@google.com virtual ~SimpleThread() {} 1462SN/A 14713865Sgabeblack@google.com void takeOverFrom(ThreadContext *oldContext) override; 148180SN/A 14913865Sgabeblack@google.com void regStats(const std::string &name) override; 1502SN/A 1512862Sktlim@umich.edu void copyState(ThreadContext *oldContext); 1522862Sktlim@umich.edu 15311168Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override; 15411168Sandreas.hansson@arm.com void unserialize(CheckpointIn &cp) override; 1559461Snilay@cs.wisc.edu void startup(); 156217SN/A 1572683Sktlim@umich.edu /*************************************************************** 1582683Sktlim@umich.edu * SimpleThread functions to provide CPU with access to various 1595891Sgblack@eecs.umich.edu * state. 1602683Sktlim@umich.edu **************************************************************/ 1612190SN/A 1622683Sktlim@umich.edu /** Returns the pointer to this SimpleThread's ThreadContext. Used 1632683Sktlim@umich.edu * when a ThreadContext must be passed to objects outside of the 1642683Sktlim@umich.edu * CPU. 1652683Sktlim@umich.edu */ 16613865Sgabeblack@google.com ThreadContext *getTC() { return this; } 1672190SN/A 1685358Sgblack@eecs.umich.edu void demapPage(Addr vaddr, uint64_t asn) 1695358Sgblack@eecs.umich.edu { 1705358Sgblack@eecs.umich.edu itb->demapPage(vaddr, asn); 1715358Sgblack@eecs.umich.edu dtb->demapPage(vaddr, asn); 1725358Sgblack@eecs.umich.edu } 1735358Sgblack@eecs.umich.edu 1745358Sgblack@eecs.umich.edu void demapInstPage(Addr vaddr, uint64_t asn) 1755358Sgblack@eecs.umich.edu { 1765358Sgblack@eecs.umich.edu itb->demapPage(vaddr, asn); 1775358Sgblack@eecs.umich.edu } 1785358Sgblack@eecs.umich.edu 1795358Sgblack@eecs.umich.edu void demapDataPage(Addr vaddr, uint64_t asn) 1805358Sgblack@eecs.umich.edu { 1815358Sgblack@eecs.umich.edu dtb->demapPage(vaddr, asn); 1825358Sgblack@eecs.umich.edu } 1835358Sgblack@eecs.umich.edu 18413865Sgabeblack@google.com void dumpFuncProfile() override; 1852521SN/A 1865702Ssaidi@eecs.umich.edu Fault hwrei(); 1875702Ssaidi@eecs.umich.edu 1885702Ssaidi@eecs.umich.edu bool simPalCheck(int palFunc); 1895702Ssaidi@eecs.umich.edu 1902683Sktlim@umich.edu /******************************************* 1912683Sktlim@umich.edu * ThreadContext interface functions. 1922683Sktlim@umich.edu ******************************************/ 1932683Sktlim@umich.edu 19413865Sgabeblack@google.com BaseCPU *getCpuPtr() override { return baseCpu; } 1952683Sktlim@umich.edu 19613865Sgabeblack@google.com int cpuId() const override { return ThreadState::cpuId(); } 19713865Sgabeblack@google.com uint32_t socketId() const override { return ThreadState::socketId(); } 19813865Sgabeblack@google.com int threadId() const override { return ThreadState::threadId(); } 19913865Sgabeblack@google.com void setThreadId(int id) override { ThreadState::setThreadId(id); } 20013865Sgabeblack@google.com ContextID contextId() const override { return ThreadState::contextId(); } 20113865Sgabeblack@google.com void setContextId(ContextID id) override { ThreadState::setContextId(id); } 2022683Sktlim@umich.edu 20313865Sgabeblack@google.com BaseTLB *getITBPtr() override { return itb; } 2042683Sktlim@umich.edu 20513865Sgabeblack@google.com BaseTLB *getDTBPtr() override { return dtb; } 2068733Sgeoffrey.blake@arm.com 20713865Sgabeblack@google.com CheckerCPU *getCheckerCpuPtr() override { return NULL; } 20813693Sgiacomo.gabrielli@arm.com 20913865Sgabeblack@google.com TheISA::ISA *getIsaPtr() override { return isa; } 2108541Sgblack@eecs.umich.edu 21113865Sgabeblack@google.com TheISA::Decoder *getDecoderPtr() override { return &decoder; } 2124997Sgblack@eecs.umich.edu 21313865Sgabeblack@google.com System *getSystemPtr() override { return system; } 2142683Sktlim@umich.edu 21513865Sgabeblack@google.com TheISA::Kernel::Statistics * 21613875SAndrea.Mondelli@ucf.edu getKernelStats() override 21713865Sgabeblack@google.com { 21813865Sgabeblack@google.com return ThreadState::getKernelStats(); 21913865Sgabeblack@google.com } 22013865Sgabeblack@google.com 22113875SAndrea.Mondelli@ucf.edu PortProxy &getPhysProxy() override { return ThreadState::getPhysProxy(); } 22213865Sgabeblack@google.com FSTranslatingPortProxy & 22313875SAndrea.Mondelli@ucf.edu getVirtProxy() override 22413865Sgabeblack@google.com { 22513865Sgabeblack@google.com return ThreadState::getVirtProxy(); 22613865Sgabeblack@google.com } 22713865Sgabeblack@google.com 22813875SAndrea.Mondelli@ucf.edu void initMemProxies(ThreadContext *tc) override 22913875SAndrea.Mondelli@ucf.edu { 23013875SAndrea.Mondelli@ucf.edu ThreadState::initMemProxies(tc); 23113875SAndrea.Mondelli@ucf.edu } 23213875SAndrea.Mondelli@ucf.edu 23313865Sgabeblack@google.com SETranslatingPortProxy & 23413875SAndrea.Mondelli@ucf.edu getMemProxy() override 23513865Sgabeblack@google.com { 23613865Sgabeblack@google.com return ThreadState::getMemProxy(); 23713865Sgabeblack@google.com } 23813865Sgabeblack@google.com 23913875SAndrea.Mondelli@ucf.edu Process *getProcessPtr() override { return ThreadState::getProcessPtr(); } 24013865Sgabeblack@google.com void setProcessPtr(Process *p) override { ThreadState::setProcessPtr(p); } 24113865Sgabeblack@google.com 24213865Sgabeblack@google.com Status status() const override { return _status; } 24313865Sgabeblack@google.com 24413865Sgabeblack@google.com void setStatus(Status newStatus) override { _status = newStatus; } 2452683Sktlim@umich.edu 24610407Smitch.hayenga@arm.com /// Set the status to Active. 24713865Sgabeblack@google.com void activate() override; 2482683Sktlim@umich.edu 2492683Sktlim@umich.edu /// Set the status to Suspended. 25013865Sgabeblack@google.com void suspend() override; 2512683Sktlim@umich.edu 2522683Sktlim@umich.edu /// Set the status to Halted. 25313865Sgabeblack@google.com void halt() override; 2542683Sktlim@umich.edu 25513865Sgabeblack@google.com EndQuiesceEvent * 25613865Sgabeblack@google.com getQuiesceEvent() override 25713865Sgabeblack@google.com { 25813865Sgabeblack@google.com return ThreadState::getQuiesceEvent(); 25913865Sgabeblack@google.com } 2602190SN/A 26113865Sgabeblack@google.com Tick 26213865Sgabeblack@google.com readLastActivate() override 26313865Sgabeblack@google.com { 26413865Sgabeblack@google.com return ThreadState::readLastActivate(); 26513865Sgabeblack@google.com } 26613865Sgabeblack@google.com Tick 26713865Sgabeblack@google.com readLastSuspend() override 26813865Sgabeblack@google.com { 26913865Sgabeblack@google.com return ThreadState::readLastSuspend(); 27013865Sgabeblack@google.com } 27113865Sgabeblack@google.com 27213865Sgabeblack@google.com void profileClear() override { ThreadState::profileClear(); } 27313865Sgabeblack@google.com void profileSample() override { ThreadState::profileSample(); } 27413865Sgabeblack@google.com 27513865Sgabeblack@google.com void copyArchRegs(ThreadContext *tc) override; 27613865Sgabeblack@google.com 27713865Sgabeblack@google.com void clearArchRegs() override 2786315Sgblack@eecs.umich.edu { 2797720Sgblack@eecs.umich.edu _pcState = 0; 2806316Sgblack@eecs.umich.edu memset(intRegs, 0, sizeof(intRegs)); 28113501Sgabeblack@google.com memset(floatRegs, 0, sizeof(floatRegs)); 28212109SRekai.GonzalezAlberquilla@arm.com for (int i = 0; i < TheISA::NumVecRegs; i++) { 28312109SRekai.GonzalezAlberquilla@arm.com vecRegs[i].zero(); 28412109SRekai.GonzalezAlberquilla@arm.com } 28513610Sgiacomo.gabrielli@arm.com for (int i = 0; i < TheISA::NumVecPredRegs; i++) { 28613610Sgiacomo.gabrielli@arm.com vecPredRegs[i].reset(); 28713610Sgiacomo.gabrielli@arm.com } 2889920Syasuko.eckert@amd.com#ifdef ISA_HAS_CC_REGS 2899920Syasuko.eckert@amd.com memset(ccRegs, 0, sizeof(ccRegs)); 2909920Syasuko.eckert@amd.com#endif 2919384SAndreas.Sandberg@arm.com isa->clear(); 2926315Sgblack@eecs.umich.edu } 2932190SN/A 2942SN/A // 2952SN/A // New accessors for new decoder. 2962SN/A // 29713557Sgabeblack@google.com RegVal 29813865Sgabeblack@google.com readIntReg(RegIndex reg_idx) const override 2992SN/A { 3009384SAndreas.Sandberg@arm.com int flatIndex = isa->flattenIntIndex(reg_idx); 3016323Sgblack@eecs.umich.edu assert(flatIndex < TheISA::NumIntRegs); 3029426SAndreas.Sandberg@ARM.com uint64_t regVal(readIntRegFlat(flatIndex)); 3037601Sminkyu.jeong@arm.com DPRINTF(IntRegs, "Reading int reg %d (%d) as %#x.\n", 3047601Sminkyu.jeong@arm.com reg_idx, flatIndex, regVal); 3056418Sgblack@eecs.umich.edu return regVal; 3062SN/A } 3072SN/A 30813557Sgabeblack@google.com RegVal 30913865Sgabeblack@google.com readFloatReg(RegIndex reg_idx) const override 3102455SN/A { 3119384SAndreas.Sandberg@arm.com int flatIndex = isa->flattenFloatIndex(reg_idx); 3126323Sgblack@eecs.umich.edu assert(flatIndex < TheISA::NumFloatRegs); 31313611Sgabeblack@google.com RegVal regVal(readFloatRegFlat(flatIndex)); 31413501Sgabeblack@google.com DPRINTF(FloatRegs, "Reading float reg %d (%d) bits as %#x.\n", 31513501Sgabeblack@google.com reg_idx, flatIndex, regVal); 3167341Sgblack@eecs.umich.edu return regVal; 3172SN/A } 3182SN/A 31912109SRekai.GonzalezAlberquilla@arm.com const VecRegContainer& 32013865Sgabeblack@google.com readVecReg(const RegId& reg) const override 32112109SRekai.GonzalezAlberquilla@arm.com { 32212109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecIndex(reg.index()); 32312109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 32412109SRekai.GonzalezAlberquilla@arm.com const VecRegContainer& regVal = readVecRegFlat(flatIndex); 32512109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Reading vector reg %d (%d) as %s.\n", 32613610Sgiacomo.gabrielli@arm.com reg.index(), flatIndex, regVal.print()); 32712109SRekai.GonzalezAlberquilla@arm.com return regVal; 32812109SRekai.GonzalezAlberquilla@arm.com } 32912109SRekai.GonzalezAlberquilla@arm.com 33012109SRekai.GonzalezAlberquilla@arm.com VecRegContainer& 33113865Sgabeblack@google.com getWritableVecReg(const RegId& reg) override 33212109SRekai.GonzalezAlberquilla@arm.com { 33312109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecIndex(reg.index()); 33412109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 33512109SRekai.GonzalezAlberquilla@arm.com VecRegContainer& regVal = getWritableVecRegFlat(flatIndex); 33612109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Reading vector reg %d (%d) as %s for modify.\n", 33713610Sgiacomo.gabrielli@arm.com reg.index(), flatIndex, regVal.print()); 33812109SRekai.GonzalezAlberquilla@arm.com return regVal; 33912109SRekai.GonzalezAlberquilla@arm.com } 34012109SRekai.GonzalezAlberquilla@arm.com 34112109SRekai.GonzalezAlberquilla@arm.com /** Vector Register Lane Interfaces. */ 34212109SRekai.GonzalezAlberquilla@arm.com /** @{ */ 34312109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector <T> operand. */ 34412109SRekai.GonzalezAlberquilla@arm.com template <typename T> 34512109SRekai.GonzalezAlberquilla@arm.com VecLaneT<T, true> 34612109SRekai.GonzalezAlberquilla@arm.com readVecLane(const RegId& reg) const 34712109SRekai.GonzalezAlberquilla@arm.com { 34812109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecIndex(reg.index()); 34912109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 35012109SRekai.GonzalezAlberquilla@arm.com auto regVal = readVecLaneFlat<T>(flatIndex, reg.elemIndex()); 35112109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Reading vector lane %d (%d)[%d] as %lx.\n", 35212109SRekai.GonzalezAlberquilla@arm.com reg.index(), flatIndex, reg.elemIndex(), regVal); 35312109SRekai.GonzalezAlberquilla@arm.com return regVal; 35412109SRekai.GonzalezAlberquilla@arm.com } 35512109SRekai.GonzalezAlberquilla@arm.com 35612109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 8bit operand. */ 35712109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane8 35813865Sgabeblack@google.com readVec8BitLaneReg(const RegId ®) const override 35913865Sgabeblack@google.com { 36013865Sgabeblack@google.com return readVecLane<uint8_t>(reg); 36113865Sgabeblack@google.com } 36212109SRekai.GonzalezAlberquilla@arm.com 36312109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 16bit operand. */ 36412109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane16 36513865Sgabeblack@google.com readVec16BitLaneReg(const RegId ®) const override 36613865Sgabeblack@google.com { 36713865Sgabeblack@google.com return readVecLane<uint16_t>(reg); 36813865Sgabeblack@google.com } 36912109SRekai.GonzalezAlberquilla@arm.com 37012109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 32bit operand. */ 37112109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane32 37213865Sgabeblack@google.com readVec32BitLaneReg(const RegId ®) const override 37313865Sgabeblack@google.com { 37413865Sgabeblack@google.com return readVecLane<uint32_t>(reg); 37513865Sgabeblack@google.com } 37612109SRekai.GonzalezAlberquilla@arm.com 37712109SRekai.GonzalezAlberquilla@arm.com /** Reads source vector 64bit operand. */ 37812109SRekai.GonzalezAlberquilla@arm.com virtual ConstVecLane64 37913865Sgabeblack@google.com readVec64BitLaneReg(const RegId ®) const override 38013865Sgabeblack@google.com { 38113865Sgabeblack@google.com return readVecLane<uint64_t>(reg); 38213865Sgabeblack@google.com } 38312109SRekai.GonzalezAlberquilla@arm.com 38412109SRekai.GonzalezAlberquilla@arm.com /** Write a lane of the destination vector register. */ 38512109SRekai.GonzalezAlberquilla@arm.com template <typename LD> 38613865Sgabeblack@google.com void 38713865Sgabeblack@google.com setVecLaneT(const RegId ®, const LD &val) 38812109SRekai.GonzalezAlberquilla@arm.com { 38912109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecIndex(reg.index()); 39012109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 39112109SRekai.GonzalezAlberquilla@arm.com setVecLaneFlat(flatIndex, reg.elemIndex(), val); 39212109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Reading vector lane %d (%d)[%d] to %lx.\n", 39312109SRekai.GonzalezAlberquilla@arm.com reg.index(), flatIndex, reg.elemIndex(), val); 39412109SRekai.GonzalezAlberquilla@arm.com } 39513865Sgabeblack@google.com virtual void 39613865Sgabeblack@google.com setVecLane(const RegId ®, const LaneData<LaneSize::Byte> &val) override 39713865Sgabeblack@google.com { 39813865Sgabeblack@google.com return setVecLaneT(reg, val); 39913865Sgabeblack@google.com } 40013865Sgabeblack@google.com virtual void 40113865Sgabeblack@google.com setVecLane(const RegId ®, 40213865Sgabeblack@google.com const LaneData<LaneSize::TwoByte> &val) override 40313865Sgabeblack@google.com { 40413865Sgabeblack@google.com return setVecLaneT(reg, val); 40513865Sgabeblack@google.com } 40613865Sgabeblack@google.com virtual void 40713865Sgabeblack@google.com setVecLane(const RegId ®, 40813865Sgabeblack@google.com const LaneData<LaneSize::FourByte> &val) override 40913865Sgabeblack@google.com { 41013865Sgabeblack@google.com return setVecLaneT(reg, val); 41113865Sgabeblack@google.com } 41213865Sgabeblack@google.com virtual void 41313865Sgabeblack@google.com setVecLane(const RegId ®, 41413865Sgabeblack@google.com const LaneData<LaneSize::EightByte> &val) override 41513865Sgabeblack@google.com { 41613865Sgabeblack@google.com return setVecLaneT(reg, val); 41713865Sgabeblack@google.com } 41812109SRekai.GonzalezAlberquilla@arm.com /** @} */ 41912109SRekai.GonzalezAlberquilla@arm.com 42013865Sgabeblack@google.com const VecElem & 42113865Sgabeblack@google.com readVecElem(const RegId ®) const override 42212109SRekai.GonzalezAlberquilla@arm.com { 42312109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecElemIndex(reg.index()); 42412109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 42512109SRekai.GonzalezAlberquilla@arm.com const VecElem& regVal = readVecElemFlat(flatIndex, reg.elemIndex()); 42612109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Reading element %d of vector reg %d (%d) as" 42712109SRekai.GonzalezAlberquilla@arm.com " %#x.\n", reg.elemIndex(), reg.index(), flatIndex, regVal); 42812109SRekai.GonzalezAlberquilla@arm.com return regVal; 42912109SRekai.GonzalezAlberquilla@arm.com } 43012109SRekai.GonzalezAlberquilla@arm.com 43113865Sgabeblack@google.com const VecPredRegContainer & 43213865Sgabeblack@google.com readVecPredReg(const RegId ®) const override 43313610Sgiacomo.gabrielli@arm.com { 43413610Sgiacomo.gabrielli@arm.com int flatIndex = isa->flattenVecPredIndex(reg.index()); 43513610Sgiacomo.gabrielli@arm.com assert(flatIndex < TheISA::NumVecPredRegs); 43613610Sgiacomo.gabrielli@arm.com const VecPredRegContainer& regVal = readVecPredRegFlat(flatIndex); 43713610Sgiacomo.gabrielli@arm.com DPRINTF(VecPredRegs, "Reading predicate reg %d (%d) as %s.\n", 43813610Sgiacomo.gabrielli@arm.com reg.index(), flatIndex, regVal.print()); 43913610Sgiacomo.gabrielli@arm.com return regVal; 44013610Sgiacomo.gabrielli@arm.com } 44113610Sgiacomo.gabrielli@arm.com 44213865Sgabeblack@google.com VecPredRegContainer & 44313865Sgabeblack@google.com getWritableVecPredReg(const RegId ®) override 44413610Sgiacomo.gabrielli@arm.com { 44513610Sgiacomo.gabrielli@arm.com int flatIndex = isa->flattenVecPredIndex(reg.index()); 44613610Sgiacomo.gabrielli@arm.com assert(flatIndex < TheISA::NumVecPredRegs); 44713610Sgiacomo.gabrielli@arm.com VecPredRegContainer& regVal = getWritableVecPredRegFlat(flatIndex); 44813610Sgiacomo.gabrielli@arm.com DPRINTF(VecPredRegs, 44913610Sgiacomo.gabrielli@arm.com "Reading predicate reg %d (%d) as %s for modify.\n", 45013610Sgiacomo.gabrielli@arm.com reg.index(), flatIndex, regVal.print()); 45113610Sgiacomo.gabrielli@arm.com return regVal; 45213610Sgiacomo.gabrielli@arm.com } 45312109SRekai.GonzalezAlberquilla@arm.com 45413622Sgabeblack@google.com RegVal 45513865Sgabeblack@google.com readCCReg(RegIndex reg_idx) const override 4569920Syasuko.eckert@amd.com { 4579920Syasuko.eckert@amd.com#ifdef ISA_HAS_CC_REGS 4589920Syasuko.eckert@amd.com int flatIndex = isa->flattenCCIndex(reg_idx); 45910338SCurtis.Dunham@arm.com assert(0 <= flatIndex); 4609920Syasuko.eckert@amd.com assert(flatIndex < TheISA::NumCCRegs); 4619920Syasuko.eckert@amd.com uint64_t regVal(readCCRegFlat(flatIndex)); 4629920Syasuko.eckert@amd.com DPRINTF(CCRegs, "Reading CC reg %d (%d) as %#x.\n", 4639920Syasuko.eckert@amd.com reg_idx, flatIndex, regVal); 4649920Syasuko.eckert@amd.com return regVal; 4659920Syasuko.eckert@amd.com#else 4669920Syasuko.eckert@amd.com panic("Tried to read a CC register."); 4679920Syasuko.eckert@amd.com return 0; 4689920Syasuko.eckert@amd.com#endif 4699920Syasuko.eckert@amd.com } 4709920Syasuko.eckert@amd.com 47113557Sgabeblack@google.com void 47213865Sgabeblack@google.com setIntReg(RegIndex reg_idx, RegVal val) override 4732SN/A { 4749384SAndreas.Sandberg@arm.com int flatIndex = isa->flattenIntIndex(reg_idx); 4756323Sgblack@eecs.umich.edu assert(flatIndex < TheISA::NumIntRegs); 4767601Sminkyu.jeong@arm.com DPRINTF(IntRegs, "Setting int reg %d (%d) to %#x.\n", 4777601Sminkyu.jeong@arm.com reg_idx, flatIndex, val); 4789426SAndreas.Sandberg@ARM.com setIntRegFlat(flatIndex, val); 4792SN/A } 4802SN/A 48113557Sgabeblack@google.com void 48213865Sgabeblack@google.com setFloatReg(RegIndex reg_idx, RegVal val) override 4832455SN/A { 4849384SAndreas.Sandberg@arm.com int flatIndex = isa->flattenFloatIndex(reg_idx); 4856323Sgblack@eecs.umich.edu assert(flatIndex < TheISA::NumFloatRegs); 4868733Sgeoffrey.blake@arm.com // XXX: Fix array out of bounds compiler error for gem5.fast 4878733Sgeoffrey.blake@arm.com // when checkercpu enabled 4888733Sgeoffrey.blake@arm.com if (flatIndex < TheISA::NumFloatRegs) 48913611Sgabeblack@google.com setFloatRegFlat(flatIndex, val); 49013501Sgabeblack@google.com DPRINTF(FloatRegs, "Setting float reg %d (%d) bits to %#x.\n", 49113501Sgabeblack@google.com reg_idx, flatIndex, val); 4922SN/A } 4932SN/A 49413557Sgabeblack@google.com void 49513865Sgabeblack@google.com setVecReg(const RegId ®, const VecRegContainer &val) override 49612109SRekai.GonzalezAlberquilla@arm.com { 49712109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecIndex(reg.index()); 49812109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 49912109SRekai.GonzalezAlberquilla@arm.com setVecRegFlat(flatIndex, val); 50012109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Setting vector reg %d (%d) to %s.\n", 50112109SRekai.GonzalezAlberquilla@arm.com reg.index(), flatIndex, val.print()); 50212109SRekai.GonzalezAlberquilla@arm.com } 50312109SRekai.GonzalezAlberquilla@arm.com 50413557Sgabeblack@google.com void 50513865Sgabeblack@google.com setVecElem(const RegId ®, const VecElem &val) override 50612109SRekai.GonzalezAlberquilla@arm.com { 50712109SRekai.GonzalezAlberquilla@arm.com int flatIndex = isa->flattenVecElemIndex(reg.index()); 50812109SRekai.GonzalezAlberquilla@arm.com assert(flatIndex < TheISA::NumVecRegs); 50912109SRekai.GonzalezAlberquilla@arm.com setVecElemFlat(flatIndex, reg.elemIndex(), val); 51012109SRekai.GonzalezAlberquilla@arm.com DPRINTF(VecRegs, "Setting element %d of vector reg %d (%d) to" 51112109SRekai.GonzalezAlberquilla@arm.com " %#x.\n", reg.elemIndex(), reg.index(), flatIndex, val); 51212109SRekai.GonzalezAlberquilla@arm.com } 51312109SRekai.GonzalezAlberquilla@arm.com 51413557Sgabeblack@google.com void 51513865Sgabeblack@google.com setVecPredReg(const RegId ®, const VecPredRegContainer &val) override 51613610Sgiacomo.gabrielli@arm.com { 51713610Sgiacomo.gabrielli@arm.com int flatIndex = isa->flattenVecPredIndex(reg.index()); 51813610Sgiacomo.gabrielli@arm.com assert(flatIndex < TheISA::NumVecPredRegs); 51913610Sgiacomo.gabrielli@arm.com setVecPredRegFlat(flatIndex, val); 52013610Sgiacomo.gabrielli@arm.com DPRINTF(VecPredRegs, "Setting predicate reg %d (%d) to %s.\n", 52113610Sgiacomo.gabrielli@arm.com reg.index(), flatIndex, val.print()); 52213610Sgiacomo.gabrielli@arm.com } 52313610Sgiacomo.gabrielli@arm.com 52413610Sgiacomo.gabrielli@arm.com void 52513865Sgabeblack@google.com setCCReg(RegIndex reg_idx, RegVal val) override 5269920Syasuko.eckert@amd.com { 5279920Syasuko.eckert@amd.com#ifdef ISA_HAS_CC_REGS 5289920Syasuko.eckert@amd.com int flatIndex = isa->flattenCCIndex(reg_idx); 5299920Syasuko.eckert@amd.com assert(flatIndex < TheISA::NumCCRegs); 5309920Syasuko.eckert@amd.com DPRINTF(CCRegs, "Setting CC reg %d (%d) to %#x.\n", 5319920Syasuko.eckert@amd.com reg_idx, flatIndex, val); 5329920Syasuko.eckert@amd.com setCCRegFlat(flatIndex, val); 5339920Syasuko.eckert@amd.com#else 5349920Syasuko.eckert@amd.com panic("Tried to set a CC register."); 5359920Syasuko.eckert@amd.com#endif 5369920Syasuko.eckert@amd.com } 5379920Syasuko.eckert@amd.com 53813865Sgabeblack@google.com TheISA::PCState pcState() const override { return _pcState; } 53913865Sgabeblack@google.com void pcState(const TheISA::PCState &val) override { _pcState = val; } 5402SN/A 5417720Sgblack@eecs.umich.edu void 54213865Sgabeblack@google.com pcStateNoRecord(const TheISA::PCState &val) override 5432190SN/A { 5447720Sgblack@eecs.umich.edu _pcState = val; 5452190SN/A } 5462190SN/A 54713865Sgabeblack@google.com Addr instAddr() const override { return _pcState.instAddr(); } 54813865Sgabeblack@google.com Addr nextInstAddr() const override { return _pcState.nextInstAddr(); } 54913865Sgabeblack@google.com MicroPC microPC() const override { return _pcState.microPC(); } 55013865Sgabeblack@google.com bool readPredicate() const { return predicate; } 55113865Sgabeblack@google.com void setPredicate(bool val) { predicate = val; } 5527597Sminkyu.jeong@arm.com 55313557Sgabeblack@google.com RegVal 55413865Sgabeblack@google.com readMiscRegNoEffect(RegIndex misc_reg) const override 5554172Ssaidi@eecs.umich.edu { 5569384SAndreas.Sandberg@arm.com return isa->readMiscRegNoEffect(misc_reg); 5574172Ssaidi@eecs.umich.edu } 5584172Ssaidi@eecs.umich.edu 55913557Sgabeblack@google.com RegVal 56013865Sgabeblack@google.com readMiscReg(RegIndex misc_reg) override 5612SN/A { 56213865Sgabeblack@google.com return isa->readMiscReg(misc_reg, this); 5632SN/A } 5642SN/A 5656221Snate@binkert.org void 56613865Sgabeblack@google.com setMiscRegNoEffect(RegIndex misc_reg, RegVal val) override 5672SN/A { 5689384SAndreas.Sandberg@arm.com return isa->setMiscRegNoEffect(misc_reg, val); 5692SN/A } 5702SN/A 5716221Snate@binkert.org void 57213865Sgabeblack@google.com setMiscReg(RegIndex misc_reg, RegVal val) override 5732SN/A { 57413865Sgabeblack@google.com return isa->setMiscReg(misc_reg, val, this); 5756313Sgblack@eecs.umich.edu } 5766313Sgblack@eecs.umich.edu 57712106SRekai.GonzalezAlberquilla@arm.com RegId 57813865Sgabeblack@google.com flattenRegId(const RegId& regId) const override 5796313Sgblack@eecs.umich.edu { 58012106SRekai.GonzalezAlberquilla@arm.com return isa->flattenRegId(regId); 58110033SAli.Saidi@ARM.com } 58210033SAli.Saidi@ARM.com 58313865Sgabeblack@google.com unsigned readStCondFailures() const override { return storeCondFailures; } 5842190SN/A 58513557Sgabeblack@google.com void 58613865Sgabeblack@google.com setStCondFailures(unsigned sc_failures) override 5872SN/A { 58813865Sgabeblack@google.com storeCondFailures = sc_failures; 5892SN/A } 5909426SAndreas.Sandberg@ARM.com 59113865Sgabeblack@google.com Counter 59213865Sgabeblack@google.com readFuncExeInst() const override 59313865Sgabeblack@google.com { 59413865Sgabeblack@google.com return ThreadState::readFuncExeInst(); 59513865Sgabeblack@google.com } 5969426SAndreas.Sandberg@ARM.com 59713865Sgabeblack@google.com void 59813865Sgabeblack@google.com syscall(int64_t callnum, Fault *fault) override 59913865Sgabeblack@google.com { 60013865Sgabeblack@google.com process->syscall(callnum, this, fault); 60113865Sgabeblack@google.com } 60213865Sgabeblack@google.com 60313865Sgabeblack@google.com RegVal readIntRegFlat(RegIndex idx) const override { return intRegs[idx]; } 60413865Sgabeblack@google.com void 60513865Sgabeblack@google.com setIntRegFlat(RegIndex idx, RegVal val) override 60613865Sgabeblack@google.com { 60713865Sgabeblack@google.com intRegs[idx] = val; 60813865Sgabeblack@google.com } 60913865Sgabeblack@google.com 61013865Sgabeblack@google.com RegVal 61113865Sgabeblack@google.com readFloatRegFlat(RegIndex idx) const override 61213865Sgabeblack@google.com { 61313865Sgabeblack@google.com return floatRegs[idx]; 61413865Sgabeblack@google.com } 61513865Sgabeblack@google.com void 61613865Sgabeblack@google.com setFloatRegFlat(RegIndex idx, RegVal val) override 61713865Sgabeblack@google.com { 61813865Sgabeblack@google.com floatRegs[idx] = val; 61913865Sgabeblack@google.com } 6209426SAndreas.Sandberg@ARM.com 62113557Sgabeblack@google.com const VecRegContainer & 62213865Sgabeblack@google.com readVecRegFlat(RegIndex reg) const override 62312109SRekai.GonzalezAlberquilla@arm.com { 62412109SRekai.GonzalezAlberquilla@arm.com return vecRegs[reg]; 62512109SRekai.GonzalezAlberquilla@arm.com } 62612109SRekai.GonzalezAlberquilla@arm.com 62713557Sgabeblack@google.com VecRegContainer & 62813865Sgabeblack@google.com getWritableVecRegFlat(RegIndex reg) override 62912109SRekai.GonzalezAlberquilla@arm.com { 63012109SRekai.GonzalezAlberquilla@arm.com return vecRegs[reg]; 63112109SRekai.GonzalezAlberquilla@arm.com } 63212109SRekai.GonzalezAlberquilla@arm.com 63313557Sgabeblack@google.com void 63413865Sgabeblack@google.com setVecRegFlat(RegIndex reg, const VecRegContainer &val) override 63512109SRekai.GonzalezAlberquilla@arm.com { 63612109SRekai.GonzalezAlberquilla@arm.com vecRegs[reg] = val; 63712109SRekai.GonzalezAlberquilla@arm.com } 63812109SRekai.GonzalezAlberquilla@arm.com 63912109SRekai.GonzalezAlberquilla@arm.com template <typename T> 64013557Sgabeblack@google.com VecLaneT<T, true> 64113865Sgabeblack@google.com readVecLaneFlat(RegIndex reg, int lId) const 64212109SRekai.GonzalezAlberquilla@arm.com { 64312109SRekai.GonzalezAlberquilla@arm.com return vecRegs[reg].laneView<T>(lId); 64412109SRekai.GonzalezAlberquilla@arm.com } 64512109SRekai.GonzalezAlberquilla@arm.com 64612109SRekai.GonzalezAlberquilla@arm.com template <typename LD> 64713557Sgabeblack@google.com void 64813865Sgabeblack@google.com setVecLaneFlat(RegIndex reg, int lId, const LD &val) 64912109SRekai.GonzalezAlberquilla@arm.com { 65012109SRekai.GonzalezAlberquilla@arm.com vecRegs[reg].laneView<typename LD::UnderlyingType>(lId) = val; 65112109SRekai.GonzalezAlberquilla@arm.com } 65212109SRekai.GonzalezAlberquilla@arm.com 65313557Sgabeblack@google.com const VecElem & 65413865Sgabeblack@google.com readVecElemFlat(RegIndex reg, const ElemIndex &elemIndex) const override 65512109SRekai.GonzalezAlberquilla@arm.com { 65612109SRekai.GonzalezAlberquilla@arm.com return vecRegs[reg].as<TheISA::VecElem>()[elemIndex]; 65712109SRekai.GonzalezAlberquilla@arm.com } 65812109SRekai.GonzalezAlberquilla@arm.com 65913557Sgabeblack@google.com void 66013865Sgabeblack@google.com setVecElemFlat(RegIndex reg, const ElemIndex &elemIndex, 66113865Sgabeblack@google.com const VecElem &val) override 66212109SRekai.GonzalezAlberquilla@arm.com { 66312109SRekai.GonzalezAlberquilla@arm.com vecRegs[reg].as<TheISA::VecElem>()[elemIndex] = val; 66412109SRekai.GonzalezAlberquilla@arm.com } 66512109SRekai.GonzalezAlberquilla@arm.com 66613865Sgabeblack@google.com const VecPredRegContainer & 66713865Sgabeblack@google.com readVecPredRegFlat(RegIndex reg) const override 66813610Sgiacomo.gabrielli@arm.com { 66913610Sgiacomo.gabrielli@arm.com return vecPredRegs[reg]; 67013610Sgiacomo.gabrielli@arm.com } 67113610Sgiacomo.gabrielli@arm.com 67213865Sgabeblack@google.com VecPredRegContainer & 67313865Sgabeblack@google.com getWritableVecPredRegFlat(RegIndex reg) override 67413610Sgiacomo.gabrielli@arm.com { 67513610Sgiacomo.gabrielli@arm.com return vecPredRegs[reg]; 67613610Sgiacomo.gabrielli@arm.com } 67713610Sgiacomo.gabrielli@arm.com 67813865Sgabeblack@google.com void 67913865Sgabeblack@google.com setVecPredRegFlat(RegIndex reg, const VecPredRegContainer &val) override 68013610Sgiacomo.gabrielli@arm.com { 68113610Sgiacomo.gabrielli@arm.com vecPredRegs[reg] = val; 68213610Sgiacomo.gabrielli@arm.com } 68313610Sgiacomo.gabrielli@arm.com 6849920Syasuko.eckert@amd.com#ifdef ISA_HAS_CC_REGS 68513865Sgabeblack@google.com RegVal readCCRegFlat(RegIndex idx) const override { return ccRegs[idx]; } 68613865Sgabeblack@google.com void setCCRegFlat(RegIndex idx, RegVal val) override { ccRegs[idx] = val; } 6879920Syasuko.eckert@amd.com#else 68813865Sgabeblack@google.com RegVal 68913865Sgabeblack@google.com readCCRegFlat(RegIndex idx) const override 69013865Sgabeblack@google.com { 69113865Sgabeblack@google.com panic("readCCRegFlat w/no CC regs!\n"); 69213865Sgabeblack@google.com } 6939920Syasuko.eckert@amd.com 69413865Sgabeblack@google.com void 69513865Sgabeblack@google.com setCCRegFlat(RegIndex idx, RegVal val) override 69613865Sgabeblack@google.com { 69713865Sgabeblack@google.com panic("setCCRegFlat w/no CC regs!\n"); 69813865Sgabeblack@google.com } 6999920Syasuko.eckert@amd.com#endif 7002SN/A}; 7012SN/A 7022SN/A 7032190SN/A#endif // __CPU_CPU_EXEC_CONTEXT_HH__ 704