exec_context.hh revision 11303
12SN/A/* 21762SN/A * Copyright (c) 2014-2015 ARM Limited 32SN/A * All rights reserved 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361354SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371354SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392SN/A * 405501Snate@binkert.org * Authors: Kevin Lim 415546Snate@binkert.org * Andreas Sandberg 427004Snate@binkert.org * Mitch Hayenga 432SN/A */ 442SN/A 4556SN/A#ifndef __CPU_SIMPLE_EXEC_CONTEXT_HH__ 465769Snate@binkert.org#define __CPU_SIMPLE_EXEC_CONTEXT_HH__ 472361SN/A 481354SN/A#include "arch/registers.hh" 496216Snate@binkert.org#include "base/types.hh" 5056SN/A#include "config/the_isa.hh" 512SN/A#include "cpu/base.hh" 525543Ssaidi@eecs.umich.edu#include "cpu/exec_context.hh" 532SN/A#include "cpu/simple/base.hh" 541354SN/A#include "cpu/static_inst_fwd.hh" 551354SN/A#include "cpu/translation.hh" 562SN/A 572SN/Aclass BaseSimpleCPU; 582SN/A 592SN/Aclass SimpleExecContext : public ExecContext { 605501Snate@binkert.org protected: 615501Snate@binkert.org typedef TheISA::MiscReg MiscReg; 622SN/A typedef TheISA::FloatReg FloatReg; 63395SN/A typedef TheISA::FloatRegBits FloatRegBits; 642SN/A typedef TheISA::CCReg CCReg; 652SN/A 662SN/A public: 675769Snate@binkert.org BaseSimpleCPU *cpu; 685769Snate@binkert.org SimpleThread* thread; 695769Snate@binkert.org 705769Snate@binkert.org // This is the offset from the current pc that fetch should be performed 715769Snate@binkert.org Addr fetchOffset; 725769Snate@binkert.org // This flag says to stay at the current pc. This is useful for 735769Snate@binkert.org // instructions which go beyond MachInst boundaries. 745769Snate@binkert.org bool stayAtPC; 755769Snate@binkert.org 765769Snate@binkert.org // Branch prediction 775769Snate@binkert.org TheISA::PCState predPC; 785769Snate@binkert.org 795774Snate@binkert.org /** PER-THREAD STATS */ 805774Snate@binkert.org 815774Snate@binkert.org // Number of simulated instructions 825769Snate@binkert.org Counter numInst; 832SN/A Stats::Scalar numInsts; 845502Snate@binkert.org Counter numOp; 855502Snate@binkert.org Stats::Scalar numOps; 865502Snate@binkert.org 875503Snate@binkert.org // Number of integer alu accesses 885503Snate@binkert.org Stats::Scalar numIntAluAccesses; 895502Snate@binkert.org 905502Snate@binkert.org // Number of float alu accesses 915502Snate@binkert.org Stats::Scalar numFpAluAccesses; 925502Snate@binkert.org 935502Snate@binkert.org // Number of function calls/returns 945502Snate@binkert.org Stats::Scalar numCallsReturns; 955502Snate@binkert.org 965602Snate@binkert.org // Conditional control instructions; 975602Snate@binkert.org Stats::Scalar numCondCtrlInsts; 985501Snate@binkert.org 995543Ssaidi@eecs.umich.edu // Number of int instructions 1005543Ssaidi@eecs.umich.edu Stats::Scalar numIntInsts; 1015769Snate@binkert.org 1024016Sstever@eecs.umich.edu // Number of float instructions 1034016Sstever@eecs.umich.edu Stats::Scalar numFpInsts; 1044016Sstever@eecs.umich.edu 1054016Sstever@eecs.umich.edu // Number of integer register file accesses 1064016Sstever@eecs.umich.edu Stats::Scalar numIntRegReads; 1074016Sstever@eecs.umich.edu Stats::Scalar numIntRegWrites; 1084016Sstever@eecs.umich.edu 1094016Sstever@eecs.umich.edu // Number of float register file accesses 1104016Sstever@eecs.umich.edu Stats::Scalar numFpRegReads; 1115501Snate@binkert.org Stats::Scalar numFpRegWrites; 1125605Snate@binkert.org 1135605Snate@binkert.org // Number of condition code register file accesses 1145605Snate@binkert.org Stats::Scalar numCCRegReads; 1155605Snate@binkert.org Stats::Scalar numCCRegWrites; 1165501Snate@binkert.org 1174016Sstever@eecs.umich.edu // Number of simulated memory references 1185577SSteve.Reinhardt@amd.com Stats::Scalar numMemRefs; 1195501Snate@binkert.org Stats::Scalar numLoadInsts; 1205501Snate@binkert.org Stats::Scalar numStoreInsts; 1215501Snate@binkert.org 1225502Snate@binkert.org // Number of idle cycles 1235502Snate@binkert.org Stats::Formula numIdleCycles; 1245605Snate@binkert.org 1255502Snate@binkert.org // Number of busy cycles 1265502Snate@binkert.org Stats::Formula numBusyCycles; 1275605Snate@binkert.org 1285605Snate@binkert.org // Number of simulated loads 1295605Snate@binkert.org Counter numLoad; 1305577SSteve.Reinhardt@amd.com 1315502Snate@binkert.org // Number of idle cycles 1325502Snate@binkert.org Stats::Average notIdleFraction; 1335502Snate@binkert.org Stats::Formula idleFraction; 1345502Snate@binkert.org 1352SN/A // Number of cycles stalled for I-cache responses 1365769Snate@binkert.org Stats::Scalar icacheStallCycles; 1375769Snate@binkert.org Counter lastIcacheStall; 1385769Snate@binkert.org 1395769Snate@binkert.org // Number of cycles stalled for D-cache responses 1405769Snate@binkert.org Stats::Scalar dcacheStallCycles; 1415769Snate@binkert.org Counter lastDcacheStall; 1422SN/A 1435769Snate@binkert.org /// @{ 1445769Snate@binkert.org /// Total number of branches fetched 1455769Snate@binkert.org Stats::Scalar numBranches; 1465769Snate@binkert.org /// Number of branches predicted as taken 1475769Snate@binkert.org Stats::Scalar numPredictedBranches; 1485769Snate@binkert.org /// Number of misprediced branches 1492SN/A Stats::Scalar numBranchMispred; 1505769Snate@binkert.org /// @} 1515769Snate@binkert.org 1525769Snate@binkert.org // Instruction mix histogram by OpClass 1535769Snate@binkert.org Stats::Vector statExecutedInstType; 1545769Snate@binkert.org 1555769Snate@binkert.org public: 1565769Snate@binkert.org /** Constructor */ 1575769Snate@binkert.org SimpleExecContext(BaseSimpleCPU* _cpu, SimpleThread* _thread) 1585769Snate@binkert.org : cpu(_cpu), thread(_thread), fetchOffset(0), stayAtPC(false), 1595769Snate@binkert.org numInst(0), numOp(0), numLoad(0), lastIcacheStall(0), lastDcacheStall(0) 1605769Snate@binkert.org { } 1615769Snate@binkert.org 1625769Snate@binkert.org /** Reads an integer register. */ 1635769Snate@binkert.org IntReg readIntRegOperand(const StaticInst *si, int idx) override 1645769Snate@binkert.org { 1655769Snate@binkert.org numIntRegReads++; 1665769Snate@binkert.org return thread->readIntReg(si->srcRegIdx(idx)); 1675769Snate@binkert.org } 1685769Snate@binkert.org 1695769Snate@binkert.org /** Sets an integer register to a value. */ 1705769Snate@binkert.org void setIntRegOperand(const StaticInst *si, int idx, IntReg val) override 1715769Snate@binkert.org { 1725769Snate@binkert.org numIntRegWrites++; 1735769Snate@binkert.org thread->setIntReg(si->destRegIdx(idx), val); 1745769Snate@binkert.org } 1755769Snate@binkert.org 1765769Snate@binkert.org /** Reads a floating point register of single register width. */ 1775769Snate@binkert.org FloatReg readFloatRegOperand(const StaticInst *si, int idx) override 1785501Snate@binkert.org { 1795543Ssaidi@eecs.umich.edu numFpRegReads++; 1802SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base; 1812SN/A return thread->readFloatReg(reg_idx); 182396SN/A } 183396SN/A 184396SN/A /** Reads a floating point register in its binary format, instead 185396SN/A * of by value. */ 186396SN/A FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) override 1875501Snate@binkert.org { 1885543Ssaidi@eecs.umich.edu numFpRegReads++; 1895501Snate@binkert.org int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base; 1903329Sstever@eecs.umich.edu return thread->readFloatRegBits(reg_idx); 1913329Sstever@eecs.umich.edu } 1923329Sstever@eecs.umich.edu 1933329Sstever@eecs.umich.edu /** Sets a floating point register of single width to a value. */ 1943329Sstever@eecs.umich.edu void setFloatRegOperand(const StaticInst *si, int idx, 1953329Sstever@eecs.umich.edu FloatReg val) override 1963329Sstever@eecs.umich.edu { 1973329Sstever@eecs.umich.edu numFpRegWrites++; 1985543Ssaidi@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base; 199396SN/A thread->setFloatReg(reg_idx, val); 2003329Sstever@eecs.umich.edu } 2013329Sstever@eecs.umich.edu 2023329Sstever@eecs.umich.edu /** Sets the bits of a floating point register of single width 2033329Sstever@eecs.umich.edu * to a binary value. */ 2045543Ssaidi@eecs.umich.edu void setFloatRegOperandBits(const StaticInst *si, int idx, 2053329Sstever@eecs.umich.edu FloatRegBits val) override 206396SN/A { 207396SN/A numFpRegWrites++; 208396SN/A int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base; 2095543Ssaidi@eecs.umich.edu thread->setFloatRegBits(reg_idx, val); 210396SN/A } 211396SN/A 2125543Ssaidi@eecs.umich.edu CCReg readCCRegOperand(const StaticInst *si, int idx) override 213396SN/A { 214396SN/A numCCRegReads++; 215396SN/A int reg_idx = si->srcRegIdx(idx) - TheISA::CC_Reg_Base; 216396SN/A return thread->readCCReg(reg_idx); 2175543Ssaidi@eecs.umich.edu } 218396SN/A 219396SN/A void setCCRegOperand(const StaticInst *si, int idx, CCReg val) override 220396SN/A { 2215543Ssaidi@eecs.umich.edu numCCRegWrites++; 222396SN/A int reg_idx = si->destRegIdx(idx) - TheISA::CC_Reg_Base; 223396SN/A thread->setCCReg(reg_idx, val); 224396SN/A } 2255543Ssaidi@eecs.umich.edu 226396SN/A MiscReg readMiscRegOperand(const StaticInst *si, int idx) override 2274075Sbinkertn@umich.edu { 2284075Sbinkertn@umich.edu numIntRegReads++; 2294075Sbinkertn@umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Misc_Reg_Base; 230396SN/A return thread->readMiscReg(reg_idx); 231396SN/A } 2325543Ssaidi@eecs.umich.edu 2335501Snate@binkert.org void setMiscRegOperand(const StaticInst *si, int idx, 2345501Snate@binkert.org const MiscReg &val) override 2355543Ssaidi@eecs.umich.edu { 236396SN/A numIntRegWrites++; 237396SN/A int reg_idx = si->destRegIdx(idx) - TheISA::Misc_Reg_Base; 2382SN/A thread->setMiscReg(reg_idx, val); 2392SN/A } 2402SN/A 2412SN/A /** 2425605Snate@binkert.org * Reads a miscellaneous register, handling any architectural 2435769Snate@binkert.org * side effects due to reading that register. 244224SN/A */ 2454016Sstever@eecs.umich.edu MiscReg readMiscReg(int misc_reg) override 2465501Snate@binkert.org { 2475605Snate@binkert.org numIntRegReads++; 2485501Snate@binkert.org return thread->readMiscReg(misc_reg); 2495501Snate@binkert.org } 2505774Snate@binkert.org 2515501Snate@binkert.org /** 2525501Snate@binkert.org * Sets a miscellaneous register, handling any architectural 2534016Sstever@eecs.umich.edu * side effects due to writing that register. 254224SN/A */ 255224SN/A void setMiscReg(int misc_reg, const MiscReg &val) override 2565768Snate@binkert.org { 2575768Snate@binkert.org numIntRegWrites++; 258265SN/A thread->setMiscReg(misc_reg, val); 2595501Snate@binkert.org } 2605501Snate@binkert.org 2615501Snate@binkert.org PCState pcState() const override 2625501Snate@binkert.org { 2635501Snate@binkert.org return thread->pcState(); 2645501Snate@binkert.org } 2655501Snate@binkert.org 2665501Snate@binkert.org void pcState(const PCState &val) override 2675501Snate@binkert.org { 2685501Snate@binkert.org thread->pcState(val); 2695501Snate@binkert.org } 2705501Snate@binkert.org 2715501Snate@binkert.org 2725501Snate@binkert.org /** 2735501Snate@binkert.org * Record the effective address of the instruction. 2745501Snate@binkert.org * 2755501Snate@binkert.org * @note Only valid for memory ops. 2765501Snate@binkert.org */ 2775501Snate@binkert.org void setEA(Addr EA) override 2785501Snate@binkert.org { panic("BaseSimpleCPU::setEA() not implemented\n"); } 2795501Snate@binkert.org 2802SN/A /** 2815769Snate@binkert.org * Get the effective address of the instruction. 2822SN/A * 2832SN/A * @note Only valid for memory ops. 2845769Snate@binkert.org */ 2852SN/A Addr getEA() const override 2862SN/A { panic("BaseSimpleCPU::getEA() not implemented\n"); } 2875769Snate@binkert.org 2882SN/A Fault readMem(Addr addr, uint8_t *data, unsigned int size, 2892667Sstever@eecs.umich.edu unsigned int flags) override 2905769Snate@binkert.org { 2912667Sstever@eecs.umich.edu return cpu->readMem(addr, data, size, flags); 2922SN/A } 2932SN/A 2942SN/A Fault initiateMemRead(Addr addr, unsigned int size, 2952SN/A unsigned int flags) override 2962SN/A { 2972SN/A return cpu->initiateMemRead(addr, size, flags); 2985605Snate@binkert.org } 2995501Snate@binkert.org 3005501Snate@binkert.org Fault writeMem(uint8_t *data, unsigned int size, Addr addr, 3012SN/A unsigned int flags, uint64_t *res) override 3025501Snate@binkert.org { 3035501Snate@binkert.org return cpu->writeMem(data, size, addr, flags, res); 3045501Snate@binkert.org } 3052SN/A 3062SN/A /** 3072SN/A * Sets the number of consecutive store conditional failures. 308224SN/A */ 309224SN/A void setStCondFailures(unsigned int sc_failures) override 310237SN/A { 3115605Snate@binkert.org thread->setStCondFailures(sc_failures); 312571SN/A } 313571SN/A 3142SN/A /** 3152SN/A * Returns the number of consecutive store conditional failures. 3162SN/A */ 317395SN/A unsigned int readStCondFailures() const override 3182SN/A { 3195605Snate@binkert.org return thread->readStCondFailures(); 320265SN/A } 3212SN/A 3222SN/A /** 3232SN/A * Executes a syscall specified by the callnum. 3242SN/A */ 3252SN/A void syscall(int64_t callnum) override 3262SN/A { 3272SN/A if (FullSystem) 328265SN/A panic("Syscall emulation isn't available in FS mode."); 3292SN/A 3302SN/A thread->syscall(callnum); 331512SN/A } 332265SN/A 3332SN/A /** Returns a pointer to the ThreadContext. */ 3345738Snate@binkert.org ThreadContext *tcBase() override 3355738Snate@binkert.org { 3365738Snate@binkert.org return thread->getTC(); 3372SN/A } 3385501Snate@binkert.org 3392667Sstever@eecs.umich.edu /** 3402SN/A * Somewhat Alpha-specific function that handles returning from an 3412SN/A * error or interrupt. 3422SN/A */ 3432SN/A Fault hwrei() override 3445501Snate@binkert.org { 3455501Snate@binkert.org return thread->hwrei(); 3465501Snate@binkert.org } 3472SN/A 3482SN/A /** 3492SN/A * Check for special simulator handling of specific PAL calls. If 3502SN/A * return value is false, actual PAL call will be suppressed. 3511634SN/A */ 3521634SN/A bool simPalCheck(int palFunc) override 3531634SN/A { 3541634SN/A return thread->simPalCheck(palFunc); 3551634SN/A } 3562SN/A 3572SN/A bool readPredicate() override 3582SN/A { 3592SN/A return thread->readPredicate(); 3602SN/A } 3612SN/A 3622SN/A void setPredicate(bool val) override 3632SN/A { 3645501Snate@binkert.org thread->setPredicate(val); 3652SN/A 3665501Snate@binkert.org if (cpu->traceData) { 3672SN/A cpu->traceData->setPredicate(val); 3682SN/A } 3692SN/A } 3705502Snate@binkert.org 3715502Snate@binkert.org /** 3725605Snate@binkert.org * Invalidate a page in the DTLB <i>and</i> ITLB. 373217SN/A */ 374237SN/A void demapPage(Addr vaddr, uint64_t asn) override 3755605Snate@binkert.org { 3762SN/A thread->demapPage(vaddr, asn); 3772SN/A } 3785605Snate@binkert.org 3795605Snate@binkert.org void armMonitor(Addr address) override 3805605Snate@binkert.org { 3815605Snate@binkert.org cpu->armMonitor(thread->threadId(), address); 3825605Snate@binkert.org } 3835605Snate@binkert.org 3842SN/A bool mwait(PacketPtr pkt) override 3855605Snate@binkert.org { 3865605Snate@binkert.org return cpu->mwait(thread->threadId(), pkt); 3875605Snate@binkert.org } 3885605Snate@binkert.org 3892SN/A void mwaitAtomic(ThreadContext *tc) override 3905605Snate@binkert.org { 3915605Snate@binkert.org cpu->mwaitAtomic(thread->threadId(), tc, thread->dtb); 3925605Snate@binkert.org } 3935605Snate@binkert.org 3945605Snate@binkert.org AddressMonitor *getAddrMonitor() override 3955605Snate@binkert.org { 3965605Snate@binkert.org return cpu->getCpuAddrMonitor(thread->threadId()); 3975605Snate@binkert.org } 3985605Snate@binkert.org 3995605Snate@binkert.org#if THE_ISA == MIPS_ISA 4005605Snate@binkert.org MiscReg readRegOtherThread(int regIdx, ThreadID tid = InvalidThreadID) 4015605Snate@binkert.org override 4025605Snate@binkert.org { 4035605Snate@binkert.org panic("Simple CPU models do not support multithreaded " 4045605Snate@binkert.org "register access."); 4055605Snate@binkert.org } 4065605Snate@binkert.org 4075605Snate@binkert.org void setRegOtherThread(int regIdx, MiscReg val, 4085605Snate@binkert.org ThreadID tid = InvalidThreadID) override 4095605Snate@binkert.org { 4105605Snate@binkert.org panic("Simple CPU models do not support multithreaded " 4115605Snate@binkert.org "register access."); 4125605Snate@binkert.org } 4135605Snate@binkert.org 4145605Snate@binkert.org#endif 4155605Snate@binkert.org 4165605Snate@binkert.org}; 4175605Snate@binkert.org 4185605Snate@binkert.org#endif // __CPU_EXEC_CONTEXT_HH__ 4195605Snate@binkert.org