exec_context.hh revision 11611
11060SN/A/* 27944SGiacomo.Gabrielli@arm.com * Copyright (c) 2011-2014 ARM Limited 37944SGiacomo.Gabrielli@arm.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 47944SGiacomo.Gabrielli@arm.com * All rights reserved 57944SGiacomo.Gabrielli@arm.com * 67944SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 77944SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 87944SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 97944SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 107944SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 117944SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 127944SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 137944SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 142702Sktlim@umich.edu * 156973Stjones1@inf.ed.ac.uk * Copyright (c) 2002-2005 The Regents of The University of Michigan 161060SN/A * All rights reserved. 171060SN/A * 181060SN/A * Redistribution and use in source and binary forms, with or without 191060SN/A * modification, are permitted provided that the following conditions are 201060SN/A * met: redistributions of source code must retain the above copyright 211060SN/A * notice, this list of conditions and the following disclaimer; 221060SN/A * redistributions in binary form must reproduce the above copyright 231060SN/A * notice, this list of conditions and the following disclaimer in the 241060SN/A * documentation and/or other materials provided with the distribution; 251060SN/A * neither the name of the copyright holders nor the names of its 261060SN/A * contributors may be used to endorse or promote products derived from 271060SN/A * this software without specific prior written permission. 281060SN/A * 291060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 301060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 311060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 321060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 331060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 341060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 351060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 361060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 371060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 381060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 391060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402665Ssaidi@eecs.umich.edu * 412665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 426973Stjones1@inf.ed.ac.uk * Dave Greene 431060SN/A * Nathan Binkert 441060SN/A * Andrew Bardsley 451464SN/A */ 461464SN/A 471060SN/A/** 482731Sktlim@umich.edu * @file 492292SN/A * 501464SN/A * ExecContext bears the exec_context interface for Minor. 518733Sgeoffrey.blake@arm.com */ 521060SN/A 537720Sgblack@eecs.umich.edu#ifndef __CPU_MINOR_EXEC_CONTEXT_HH__ 541060SN/A#define __CPU_MINOR_EXEC_CONTEXT_HH__ 551060SN/A 566658Snate@binkert.org#include "cpu/exec_context.hh" 578733Sgeoffrey.blake@arm.com#include "cpu/minor/execute.hh" 583770Sgblack@eecs.umich.edu#include "cpu/minor/pipeline.hh" 591464SN/A#include "cpu/base.hh" 601464SN/A#include "cpu/simple_thread.hh" 612669Sktlim@umich.edu#include "mem/request.hh" 621060SN/A#include "debug/MinorExecute.hh" 636973Stjones1@inf.ed.ac.uk 642669Sktlim@umich.edunamespace Minor 657678Sgblack@eecs.umich.edu{ 668817Sgblack@eecs.umich.edu 672292SN/A/* Forward declaration of Execute */ 686023Snate@binkert.orgclass Execute; 691060SN/A 701060SN/A/** ExecContext bears the exec_context interface for Minor. This nicely 711060SN/A * separates that interface from other classes such as Pipeline, MinorCPU 721060SN/A * and DynMinorInst and makes it easier to see what state is accessed by it. 731060SN/A */ 741060SN/Aclass ExecContext : public ::ExecContext 751060SN/A{ 761061SN/A public: 771060SN/A MinorCPU &cpu; 781060SN/A 791060SN/A /** ThreadState object, provides all the architectural state. */ 802733Sktlim@umich.edu SimpleThread &thread; 812733Sktlim@umich.edu 821060SN/A /** The execute stage so we can peek at its contents. */ 832292SN/A Execute &execute; 842107SN/A 852690Sktlim@umich.edu /** Instruction for the benefit of memory operations and for PC */ 862107SN/A MinorDynInstPtr inst; 872690Sktlim@umich.edu 882690Sktlim@umich.edu ExecContext ( 891060SN/A MinorCPU &cpu_, 902292SN/A SimpleThread &thread_, Execute &execute_, 912292SN/A MinorDynInstPtr inst_) : 928486Sgblack@eecs.umich.edu cpu(cpu_), 932292SN/A thread(thread_), 942292SN/A execute(execute_), 952292SN/A inst(inst_) 962292SN/A { 971060SN/A DPRINTF(MinorExecute, "ExecContext setting PC: %s\n", inst->pc); 985543Ssaidi@eecs.umich.edu pcState(inst->pc); 995543Ssaidi@eecs.umich.edu setPredicate(true); 1001060SN/A thread.setIntReg(TheISA::ZeroReg, 0); 1011060SN/A#if THE_ISA == ALPHA_ISA 1022292SN/A thread.setFloatReg(TheISA::ZeroReg, 0.0); 1032107SN/A#endif 1048502Sgblack@eecs.umich.edu } 1051060SN/A 1061060SN/A Fault 1071060SN/A initiateMemRead(Addr addr, unsigned int size, Request::Flags flags) 1081060SN/A { 1091060SN/A execute.getLSQ().pushRequest(inst, true /* load */, nullptr, 1101060SN/A size, addr, flags, NULL); 1112292SN/A return NoFault; 1121060SN/A } 1131060SN/A 1145358Sgblack@eecs.umich.edu Fault 1155358Sgblack@eecs.umich.edu writeMem(uint8_t *data, unsigned int size, Addr addr, 1165358Sgblack@eecs.umich.edu Request::Flags flags, uint64_t *res) override 1175358Sgblack@eecs.umich.edu { 1185358Sgblack@eecs.umich.edu execute.getLSQ().pushRequest(inst, false /* store */, data, 1195358Sgblack@eecs.umich.edu size, addr, flags, res); 1205358Sgblack@eecs.umich.edu return NoFault; 1215358Sgblack@eecs.umich.edu } 1225358Sgblack@eecs.umich.edu 1235358Sgblack@eecs.umich.edu IntReg 1245358Sgblack@eecs.umich.edu readIntRegOperand(const StaticInst *si, int idx) override 1255358Sgblack@eecs.umich.edu { 1265358Sgblack@eecs.umich.edu return thread.readIntReg(si->srcRegIdx(idx)); 1278444Sgblack@eecs.umich.edu } 1287520Sgblack@eecs.umich.edu 1298444Sgblack@eecs.umich.edu TheISA::FloatReg 1308444Sgblack@eecs.umich.edu readFloatRegOperand(const StaticInst *si, int idx) override 1317520Sgblack@eecs.umich.edu { 1326974Stjones1@inf.ed.ac.uk int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base; 1336974Stjones1@inf.ed.ac.uk return thread.readFloatReg(reg_idx); 1346974Stjones1@inf.ed.ac.uk } 1356974Stjones1@inf.ed.ac.uk 1366973Stjones1@inf.ed.ac.uk TheISA::FloatRegBits 1376974Stjones1@inf.ed.ac.uk readFloatRegOperandBits(const StaticInst *si, int idx) override 1386974Stjones1@inf.ed.ac.uk { 1396973Stjones1@inf.ed.ac.uk int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base; 1406973Stjones1@inf.ed.ac.uk return thread.readFloatRegBits(reg_idx); 1416973Stjones1@inf.ed.ac.uk } 1426973Stjones1@inf.ed.ac.uk 1431060SN/A void 1447944SGiacomo.Gabrielli@arm.com setIntRegOperand(const StaticInst *si, int idx, IntReg val) override 1457944SGiacomo.Gabrielli@arm.com { 1467944SGiacomo.Gabrielli@arm.com thread.setIntReg(si->destRegIdx(idx), val); 1477944SGiacomo.Gabrielli@arm.com } 1487944SGiacomo.Gabrielli@arm.com 1497944SGiacomo.Gabrielli@arm.com void 1508545Ssaidi@eecs.umich.edu setFloatRegOperand(const StaticInst *si, int idx, 1518545Ssaidi@eecs.umich.edu TheISA::FloatReg val) override 1528545Ssaidi@eecs.umich.edu { 1538545Ssaidi@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base; 1548545Ssaidi@eecs.umich.edu thread.setFloatReg(reg_idx, val); 1558545Ssaidi@eecs.umich.edu } 1568545Ssaidi@eecs.umich.edu 1578545Ssaidi@eecs.umich.edu void 1588545Ssaidi@eecs.umich.edu setFloatRegOperandBits(const StaticInst *si, int idx, 1598545Ssaidi@eecs.umich.edu TheISA::FloatRegBits val) override 1608545Ssaidi@eecs.umich.edu { 1618545Ssaidi@eecs.umich.edu int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base; 1628545Ssaidi@eecs.umich.edu thread.setFloatRegBits(reg_idx, val); 1637944SGiacomo.Gabrielli@arm.com } 1647944SGiacomo.Gabrielli@arm.com 1657944SGiacomo.Gabrielli@arm.com bool 1667944SGiacomo.Gabrielli@arm.com readPredicate() override 1677944SGiacomo.Gabrielli@arm.com { 1687944SGiacomo.Gabrielli@arm.com return thread.readPredicate(); 1697944SGiacomo.Gabrielli@arm.com } 1707944SGiacomo.Gabrielli@arm.com 1717944SGiacomo.Gabrielli@arm.com void 1727944SGiacomo.Gabrielli@arm.com setPredicate(bool val) override 1737944SGiacomo.Gabrielli@arm.com { 1747944SGiacomo.Gabrielli@arm.com thread.setPredicate(val); 1757944SGiacomo.Gabrielli@arm.com } 1767944SGiacomo.Gabrielli@arm.com 1777944SGiacomo.Gabrielli@arm.com TheISA::PCState 1787944SGiacomo.Gabrielli@arm.com pcState() const override 1797944SGiacomo.Gabrielli@arm.com { 1808733Sgeoffrey.blake@arm.com return thread.pcState(); 1818733Sgeoffrey.blake@arm.com } 1828733Sgeoffrey.blake@arm.com 1838733Sgeoffrey.blake@arm.com void 1848733Sgeoffrey.blake@arm.com pcState(const TheISA::PCState &val) override 1851684SN/A { 1861060SN/A thread.pcState(val); 1871060SN/A } 1881060SN/A 1891060SN/A TheISA::MiscReg 1902731Sktlim@umich.edu readMiscRegNoEffect(int misc_reg) const 1912731Sktlim@umich.edu { 1922731Sktlim@umich.edu return thread.readMiscRegNoEffect(misc_reg); 1932731Sktlim@umich.edu } 1942731Sktlim@umich.edu 1952731Sktlim@umich.edu TheISA::MiscReg 1962731Sktlim@umich.edu readMiscReg(int misc_reg) override 1972731Sktlim@umich.edu { 1982731Sktlim@umich.edu return thread.readMiscReg(misc_reg); 1992731Sktlim@umich.edu } 2002731Sktlim@umich.edu 2012731Sktlim@umich.edu void 2022731Sktlim@umich.edu setMiscReg(int misc_reg, const TheISA::MiscReg &val) override 2032731Sktlim@umich.edu { 2042731Sktlim@umich.edu thread.setMiscReg(misc_reg, val); 2052731Sktlim@umich.edu } 2062731Sktlim@umich.edu 2072731Sktlim@umich.edu TheISA::MiscReg 2082731Sktlim@umich.edu readMiscRegOperand(const StaticInst *si, int idx) override 2092731Sktlim@umich.edu { 2102731Sktlim@umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::Misc_Reg_Base; 2112731Sktlim@umich.edu return thread.readMiscReg(reg_idx); 2122731Sktlim@umich.edu } 2132731Sktlim@umich.edu 2142731Sktlim@umich.edu void 2152292SN/A setMiscRegOperand(const StaticInst *si, int idx, 2162731Sktlim@umich.edu const TheISA::MiscReg &val) override 2172731Sktlim@umich.edu { 2181060SN/A int reg_idx = si->destRegIdx(idx) - TheISA::Misc_Reg_Base; 2191060SN/A return thread.setMiscReg(reg_idx, val); 2206221Snate@binkert.org } 2211060SN/A 2221060SN/A Fault 2231060SN/A hwrei() override 2241060SN/A { 2252292SN/A#if THE_ISA == ALPHA_ISA 2262292SN/A return thread.hwrei(); 2272292SN/A#else 2282733Sktlim@umich.edu return NoFault; 2292733Sktlim@umich.edu#endif 2301060SN/A } 2312680Sktlim@umich.edu 2322292SN/A bool 2331060SN/A simPalCheck(int palFunc) override 2341060SN/A { 2352132SN/A#if THE_ISA == ALPHA_ISA 2361060SN/A return thread.simPalCheck(palFunc); 2372702Sktlim@umich.edu#else 2382669Sktlim@umich.edu return false; 2392292SN/A#endif 2401060SN/A } 2411060SN/A 2421060SN/A void 2438199SAli.Saidi@ARM.com syscall(int64_t callnum) override 2448199SAli.Saidi@ARM.com { 2458199SAli.Saidi@ARM.com if (FullSystem) 2464032Sktlim@umich.edu panic("Syscall emulation isn't available in FS mode.\n"); 2474032Sktlim@umich.edu 2484032Sktlim@umich.edu thread.syscall(callnum); 2491060SN/A } 2501060SN/A 2511060SN/A ThreadContext *tcBase() override { return thread.getTC(); } 2521060SN/A 2531060SN/A /* @todo, should make stCondFailures persistent somewhere */ 2541060SN/A unsigned int readStCondFailures() const override { return 0; } 2551464SN/A void setStCondFailures(unsigned int st_cond_failures) override {} 2561464SN/A 2571464SN/A ContextID contextId() { return thread.contextId(); } 2588733Sgeoffrey.blake@arm.com /* ISA-specific (or at least currently ISA singleton) functions */ 2598733Sgeoffrey.blake@arm.com 2608733Sgeoffrey.blake@arm.com /* X86: TLB twiddling */ 2618733Sgeoffrey.blake@arm.com void 2621464SN/A demapPage(Addr vaddr, uint64_t asn) override 2631060SN/A { 2648733Sgeoffrey.blake@arm.com thread.getITBPtr()->demapPage(vaddr, asn); 2658733Sgeoffrey.blake@arm.com thread.getDTBPtr()->demapPage(vaddr, asn); 2661464SN/A } 2678733Sgeoffrey.blake@arm.com 2681060SN/A TheISA::CCReg 2693326Sktlim@umich.edu readCCRegOperand(const StaticInst *si, int idx) override 2703326Sktlim@umich.edu { 2713326Sktlim@umich.edu int reg_idx = si->srcRegIdx(idx) - TheISA::CC_Reg_Base; 2727597Sminkyu.jeong@arm.com return thread.readCCReg(reg_idx); 2737597Sminkyu.jeong@arm.com } 2747597Sminkyu.jeong@arm.com 2753965Sgblack@eecs.umich.edu void 2767720Sgblack@eecs.umich.edu setCCRegOperand(const StaticInst *si, int idx, TheISA::CCReg val) override 2777720Sgblack@eecs.umich.edu { 2781060SN/A int reg_idx = si->destRegIdx(idx) - TheISA::CC_Reg_Base; 2797720Sgblack@eecs.umich.edu thread.setCCReg(reg_idx, val); 2807720Sgblack@eecs.umich.edu } 2814636Sgblack@eecs.umich.edu 2823794Sgblack@eecs.umich.edu void 2833794Sgblack@eecs.umich.edu demapInstPage(Addr vaddr, uint64_t asn) 2843794Sgblack@eecs.umich.edu { 2853965Sgblack@eecs.umich.edu thread.getITBPtr()->demapPage(vaddr, asn); 2863965Sgblack@eecs.umich.edu } 2872292SN/A 2882292SN/A void 2892292SN/A demapDataPage(Addr vaddr, uint64_t asn) 2902292SN/A { 2912292SN/A thread.getDTBPtr()->demapPage(vaddr, asn); 2922292SN/A } 2931060SN/A 2941060SN/A /* ALPHA/POWER: Effective address storage */ 2951060SN/A void setEA(Addr ea) override 2963770Sgblack@eecs.umich.edu { 2973770Sgblack@eecs.umich.edu inst->ea = ea; 2983770Sgblack@eecs.umich.edu } 2993770Sgblack@eecs.umich.edu 3003770Sgblack@eecs.umich.edu BaseCPU *getCpuPtr() { return &cpu; } 3013770Sgblack@eecs.umich.edu 3023770Sgblack@eecs.umich.edu /* POWER: Effective address storage */ 3033770Sgblack@eecs.umich.edu Addr getEA() const override 3043770Sgblack@eecs.umich.edu { 3053770Sgblack@eecs.umich.edu return inst->ea; 3063770Sgblack@eecs.umich.edu } 3073770Sgblack@eecs.umich.edu 3083770Sgblack@eecs.umich.edu /* MIPS: other thread register reading/writing */ 3093770Sgblack@eecs.umich.edu uint64_t 3103770Sgblack@eecs.umich.edu readRegOtherThread(int idx, ThreadID tid = InvalidThreadID) 3113770Sgblack@eecs.umich.edu { 3123770Sgblack@eecs.umich.edu SimpleThread *other_thread = (tid == InvalidThreadID 3133770Sgblack@eecs.umich.edu ? &thread : cpu.threads[tid]); 3143770Sgblack@eecs.umich.edu 3153770Sgblack@eecs.umich.edu if (idx < TheISA::FP_Reg_Base) { /* Integer */ 3163770Sgblack@eecs.umich.edu return other_thread->readIntReg(idx); 3173770Sgblack@eecs.umich.edu } else if (idx < TheISA::Misc_Reg_Base) { /* Float */ 3183770Sgblack@eecs.umich.edu return other_thread->readFloatRegBits(idx 3193770Sgblack@eecs.umich.edu - TheISA::FP_Reg_Base); 3203770Sgblack@eecs.umich.edu } else { /* Misc */ 3213770Sgblack@eecs.umich.edu return other_thread->readMiscReg(idx 3221060SN/A - TheISA::Misc_Reg_Base); 3233770Sgblack@eecs.umich.edu } 3243770Sgblack@eecs.umich.edu } 3253770Sgblack@eecs.umich.edu 3263770Sgblack@eecs.umich.edu void 3273770Sgblack@eecs.umich.edu setRegOtherThread(int idx, const TheISA::MiscReg &val, 3283770Sgblack@eecs.umich.edu ThreadID tid = InvalidThreadID) 3293770Sgblack@eecs.umich.edu { 3303770Sgblack@eecs.umich.edu SimpleThread *other_thread = (tid == InvalidThreadID 3313770Sgblack@eecs.umich.edu ? &thread : cpu.threads[tid]); 3323770Sgblack@eecs.umich.edu 3333770Sgblack@eecs.umich.edu if (idx < TheISA::FP_Reg_Base) { /* Integer */ 3343770Sgblack@eecs.umich.edu return other_thread->setIntReg(idx, val); 3353770Sgblack@eecs.umich.edu } else if (idx < TheISA::Misc_Reg_Base) { /* Float */ 3363770Sgblack@eecs.umich.edu return other_thread->setFloatRegBits(idx 3373770Sgblack@eecs.umich.edu - TheISA::FP_Reg_Base, val); 3383770Sgblack@eecs.umich.edu } else { /* Misc */ 3393770Sgblack@eecs.umich.edu return other_thread->setMiscReg(idx 3403770Sgblack@eecs.umich.edu - TheISA::Misc_Reg_Base, val); 3413770Sgblack@eecs.umich.edu } 3423770Sgblack@eecs.umich.edu } 3433770Sgblack@eecs.umich.edu 3443770Sgblack@eecs.umich.edu public: 3453770Sgblack@eecs.umich.edu // monitor/mwait funtions 3463770Sgblack@eecs.umich.edu void armMonitor(Addr address) override 3473770Sgblack@eecs.umich.edu { getCpuPtr()->armMonitor(inst->id.threadId, address); } 3483770Sgblack@eecs.umich.edu 3493770Sgblack@eecs.umich.edu bool mwait(PacketPtr pkt) override 3503770Sgblack@eecs.umich.edu { return getCpuPtr()->mwait(inst->id.threadId, pkt); } 3513770Sgblack@eecs.umich.edu 3523770Sgblack@eecs.umich.edu void mwaitAtomic(ThreadContext *tc) override 3533770Sgblack@eecs.umich.edu { return getCpuPtr()->mwaitAtomic(inst->id.threadId, tc, thread.dtb); } 3543770Sgblack@eecs.umich.edu 3553770Sgblack@eecs.umich.edu AddressMonitor *getAddrMonitor() override 3563770Sgblack@eecs.umich.edu { return getCpuPtr()->getCpuAddrMonitor(inst->id.threadId); } 3573770Sgblack@eecs.umich.edu}; 3583770Sgblack@eecs.umich.edu 3593770Sgblack@eecs.umich.edu} 3603770Sgblack@eecs.umich.edu 3613770Sgblack@eecs.umich.edu#endif /* __CPU_MINOR_EXEC_CONTEXT_HH__ */ 3623770Sgblack@eecs.umich.edu