mt.isa revision 9554
11689SN/A// -*- mode:c++ -*- 210785Sgope@wisc.edu 39480Snilay@cs.wisc.edu// Copyright (c) 2007 MIPS Technologies, Inc. 49480Snilay@cs.wisc.edu// All rights reserved. 510785Sgope@wisc.edu// 610785Sgope@wisc.edu// Redistribution and use in source and binary forms, with or without 710785Sgope@wisc.edu// modification, are permitted provided that the following conditions are 810785Sgope@wisc.edu// met: redistributions of source code must retain the above copyright 910785Sgope@wisc.edu// notice, this list of conditions and the following disclaimer; 1010785Sgope@wisc.edu// redistributions in binary form must reproduce the above copyright 1110785Sgope@wisc.edu// notice, this list of conditions and the following disclaimer in the 1210785Sgope@wisc.edu// documentation and/or other materials provided with the distribution; 1310785Sgope@wisc.edu// neither the name of the copyright holders nor the names of its 1410785Sgope@wisc.edu// contributors may be used to endorse or promote products derived from 1510785Sgope@wisc.edu// this software without specific prior written permission. 1610785Sgope@wisc.edu// 171689SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 181689SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 191689SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 201689SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 211689SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 221689SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 231689SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 241689SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 251689SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 261689SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 271689SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 281689SN/A// 291689SN/A// Authors: Korey Sewell 301689SN/A 311689SN/A//////////////////////////////////////////////////////////////////// 321689SN/A// 331689SN/A// MT instructions 341689SN/A// 351689SN/A 361689SN/Aoutput header {{ 371689SN/A /** 381689SN/A * Base class for MIPS MT ASE operations. 391689SN/A */ 401689SN/A class MTOp : public MipsStaticInst 412665SN/A { 422665SN/A protected: 431689SN/A 441061SN/A /// Constructor 4510785Sgope@wisc.edu MTOp(const char *mnem, MachInst _machInst, OpClass __opClass) : 461061SN/A MipsStaticInst(mnem, _machInst, __opClass), user_mode(false) 4710785Sgope@wisc.edu { 4810785Sgope@wisc.edu } 4910785Sgope@wisc.edu 5010785Sgope@wisc.edu std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 5110785Sgope@wisc.edu 5210785Sgope@wisc.edu bool user_mode; 5310785Sgope@wisc.edu }; 5410785Sgope@wisc.edu 5510785Sgope@wisc.edu class MTUserModeOp : public MTOp 5610785Sgope@wisc.edu { 5710785Sgope@wisc.edu protected: 5810785Sgope@wisc.edu 5910785Sgope@wisc.edu /// Constructor 6010785Sgope@wisc.edu MTUserModeOp(const char *mnem, MachInst _machInst, OpClass __opClass) : 6110785Sgope@wisc.edu MTOp(mnem, _machInst, __opClass) 6211432Smitch.hayenga@arm.com { 6311432Smitch.hayenga@arm.com user_mode = true; 6410785Sgope@wisc.edu } 6511433Smitch.hayenga@arm.com 6611433Smitch.hayenga@arm.com //std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const; 6711433Smitch.hayenga@arm.com }; 6811433Smitch.hayenga@arm.com}}; 6911433Smitch.hayenga@arm.com 7011433Smitch.hayenga@arm.comoutput decoder {{ 7111433Smitch.hayenga@arm.com std::string MTOp::generateDisassembly(Addr pc, const SymbolTable *symtab) const 7211433Smitch.hayenga@arm.com { 7311433Smitch.hayenga@arm.com std::stringstream ss; 7410785Sgope@wisc.edu 759480Snilay@cs.wisc.edu if (strcmp(mnemonic,"mttc0") == 0 || strcmp(mnemonic,"mftc0") == 0) { 7610785Sgope@wisc.edu ccprintf(ss, "%-10s r%d, r%d, %d", mnemonic, RT, RD, SEL); 7710785Sgope@wisc.edu } else if (strcmp(mnemonic,"mftgpr") == 0) { 7810785Sgope@wisc.edu ccprintf(ss, "%-10s r%d, r%d", mnemonic, RD, RT); 7910785Sgope@wisc.edu } else { 8010785Sgope@wisc.edu ccprintf(ss, "%-10s r%d, r%d", mnemonic, RT, RD); 8110785Sgope@wisc.edu } 8210785Sgope@wisc.edu 8311523Sdavid.guillen@arm.com return ss.str(); 8411523Sdavid.guillen@arm.com } 8510785Sgope@wisc.edu}}; 8610785Sgope@wisc.edu 8710785Sgope@wisc.eduoutput header {{ 8810785Sgope@wisc.edu void getThrRegExValues(%(CPU_exec_context)s *xc, 8910785Sgope@wisc.edu MipsISA::VPEConf0Reg &vpe_conf0, 9010785Sgope@wisc.edu MipsISA::TCBindReg &tc_bind_mt, 9110785Sgope@wisc.edu MipsISA::TCBindReg &tc_bind, 9210785Sgope@wisc.edu MipsISA::VPEControlReg &vpe_control, 9310785Sgope@wisc.edu MipsISA::MVPConf0Reg &mvp_conf0); 9410785Sgope@wisc.edu 9510785Sgope@wisc.edu void getMTExValues(%(CPU_exec_context)s *xc, MipsISA::Config3Reg &config3); 9610785Sgope@wisc.edu}}; 9710785Sgope@wisc.edu 9810785Sgope@wisc.eduoutput exec {{ 9910785Sgope@wisc.edu void getThrRegExValues(%(CPU_exec_context)s *xc, 10010785Sgope@wisc.edu VPEConf0Reg &vpe_conf0, TCBindReg &tc_bind_mt, 10110785Sgope@wisc.edu TCBindReg &tc_bind, VPEControlReg &vpe_control, 10210785Sgope@wisc.edu MVPConf0Reg &mvp_conf0) 10310785Sgope@wisc.edu { 10410785Sgope@wisc.edu vpe_conf0 = xc->readMiscReg(MISCREG_VPE_CONF0); 10510785Sgope@wisc.edu tc_bind_mt = xc->readRegOtherThread(MISCREG_TC_BIND + Ctrl_Base_DepTag); 10610785Sgope@wisc.edu tc_bind = xc->readMiscReg(MISCREG_TC_BIND); 10710785Sgope@wisc.edu vpe_control = xc->readMiscReg(MISCREG_VPE_CONTROL); 10810785Sgope@wisc.edu mvp_conf0 = xc->readMiscReg(MISCREG_MVP_CONF0); 10910785Sgope@wisc.edu } 11010785Sgope@wisc.edu 11110785Sgope@wisc.edu void getMTExValues(%(CPU_exec_context)s *xc, Config3Reg &config3) 11210785Sgope@wisc.edu { 11310785Sgope@wisc.edu config3 = xc->readMiscReg(MISCREG_CONFIG3); 11410785Sgope@wisc.edu } 11510785Sgope@wisc.edu}}; 11610785Sgope@wisc.edu 11710785Sgope@wisc.edudef template ThreadRegisterExecute {{ 11810785Sgope@wisc.edu Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const 11910785Sgope@wisc.edu { 12010785Sgope@wisc.edu Fault fault = NoFault; 12110785Sgope@wisc.edu int64_t data M5_VAR_USED; 12210785Sgope@wisc.edu %(op_decl)s; 12310785Sgope@wisc.edu %(op_rd)s; 12410785Sgope@wisc.edu 12510785Sgope@wisc.edu VPEConf0Reg vpeConf0; 12610785Sgope@wisc.edu TCBindReg tcBindMT; 12710785Sgope@wisc.edu TCBindReg tcBind; 12810785Sgope@wisc.edu VPEControlReg vpeControl; 12910785Sgope@wisc.edu MVPConf0Reg mvpConf0; 13010785Sgope@wisc.edu 13111433Smitch.hayenga@arm.com getThrRegExValues(xc, vpeConf0, tcBindMT, 13211433Smitch.hayenga@arm.com tcBind, vpeControl, mvpConf0); 13311433Smitch.hayenga@arm.com 13411433Smitch.hayenga@arm.com if (isCoprocessorEnabled(xc, 0)) { 13511433Smitch.hayenga@arm.com if (vpeConf0.mvp == 0 && tcBindMT.curVPE != tcBind.curVPE) { 13611433Smitch.hayenga@arm.com data = -1; 13711433Smitch.hayenga@arm.com } else if (vpeControl.targTC > mvpConf0.ptc) { 13811433Smitch.hayenga@arm.com data = -1; 13911433Smitch.hayenga@arm.com } else { 14011433Smitch.hayenga@arm.com %(code)s; 14111433Smitch.hayenga@arm.com } 14211433Smitch.hayenga@arm.com } else { 14311433Smitch.hayenga@arm.com fault = new CoprocessorUnusableFault(0); 14411433Smitch.hayenga@arm.com } 14511433Smitch.hayenga@arm.com 14611433Smitch.hayenga@arm.com if(fault == NoFault) 14711433Smitch.hayenga@arm.com { 14811433Smitch.hayenga@arm.com %(op_wb)s; 14911433Smitch.hayenga@arm.com } 15011433Smitch.hayenga@arm.com 15111433Smitch.hayenga@arm.com return fault; 15210785Sgope@wisc.edu } 15310785Sgope@wisc.edu}}; 15410785Sgope@wisc.edu 15510785Sgope@wisc.edudef template MTExecute{{ 15610785Sgope@wisc.edu Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const 15710785Sgope@wisc.edu { 15810785Sgope@wisc.edu Fault fault = NoFault; 15910785Sgope@wisc.edu %(op_decl)s; 16010785Sgope@wisc.edu %(op_rd)s; 16110785Sgope@wisc.edu 16210785Sgope@wisc.edu Config3Reg config3; 16310785Sgope@wisc.edu 16410785Sgope@wisc.edu getMTExValues(xc, config3); 16510785Sgope@wisc.edu 16610785Sgope@wisc.edu if (isCoprocessorEnabled(xc, 0)) { 16710785Sgope@wisc.edu if (config3.mt == 1) { 16810785Sgope@wisc.edu %(code)s; 16910785Sgope@wisc.edu } else { 17010785Sgope@wisc.edu fault = new ReservedInstructionFault(); 17110785Sgope@wisc.edu } 17210785Sgope@wisc.edu } else { 17310785Sgope@wisc.edu fault = new CoprocessorUnusableFault(0); 17410785Sgope@wisc.edu } 17510785Sgope@wisc.edu 17610785Sgope@wisc.edu if(fault == NoFault) 17710785Sgope@wisc.edu { 17810785Sgope@wisc.edu %(op_wb)s; 17910785Sgope@wisc.edu } 18010785Sgope@wisc.edu return fault; 18110785Sgope@wisc.edu } 18210785Sgope@wisc.edu}}; 18310785Sgope@wisc.edu 18410785Sgope@wisc.edu// Primary format for integer operate instructions: 18510785Sgope@wisc.edudef format MT_Control(code, *opt_flags) {{ 18610785Sgope@wisc.edu inst_flags = ('IsNonSpeculative', ) 18710785Sgope@wisc.edu op_type = 'MTOp' 18810785Sgope@wisc.edu 18910785Sgope@wisc.edu for x in opt_flags: 19010785Sgope@wisc.edu if x == 'UserMode': 19110785Sgope@wisc.edu op_type = 'MTUserModeOp' 19210785Sgope@wisc.edu else: 19310785Sgope@wisc.edu inst_flags += (x, ) 19410785Sgope@wisc.edu 19510785Sgope@wisc.edu iop = InstObjParams(name, Name, op_type, code, inst_flags) 19610785Sgope@wisc.edu header_output = BasicDeclare.subst(iop) 19710785Sgope@wisc.edu decoder_output = BasicConstructor.subst(iop) 19810785Sgope@wisc.edu decode_block = BasicDecode.subst(iop) 19910785Sgope@wisc.edu exec_output = MTExecute.subst(iop) 20011434Smitch.hayenga@arm.com}}; 2019480Snilay@cs.wisc.edu 20210785Sgope@wisc.edudef format MT_MFTR(code, *flags) {{ 20311434Smitch.hayenga@arm.com flags += ('IsNonSpeculative', ) 20410785Sgope@wisc.edu# code = 'std::cerr << curTick() << \": T\" << xc->tcBase()->threadId() << \": Executing MT INST: ' + name + '\" << endl;\n' + code 20510785Sgope@wisc.edu 20610785Sgope@wisc.edu code += ''' 20710785Sgope@wisc.edu if (MT_H) 20810785Sgope@wisc.edu data = bits(data, 63, 32); 20910785Sgope@wisc.edu Rd = data; 21010785Sgope@wisc.edu ''' 21110785Sgope@wisc.edu 21210785Sgope@wisc.edu iop = InstObjParams(name, Name, 'MTOp', code, flags) 21313626Sjairo.balart@metempsy.com header_output = BasicDeclare.subst(iop) 21410785Sgope@wisc.edu decoder_output = BasicConstructor.subst(iop) 21510785Sgope@wisc.edu decode_block = BasicDecode.subst(iop) 21610785Sgope@wisc.edu exec_output = ThreadRegisterExecute.subst(iop) 21710785Sgope@wisc.edu}}; 21810785Sgope@wisc.edu 21910785Sgope@wisc.edudef format MT_MTTR(code, *flags) {{ 22010785Sgope@wisc.edu flags += ('IsNonSpeculative', ) 22110785Sgope@wisc.edu# code = 'std::cerr << curTick() << \": T\" << xc->tcBase()->threadId() << \": Executing MT INST: ' + name + '\" << endl;\n' + code 22210785Sgope@wisc.edu iop = InstObjParams(name, Name, 'MTOp', code, flags) 22310785Sgope@wisc.edu header_output = BasicDeclare.subst(iop) 22410785Sgope@wisc.edu decoder_output = BasicConstructor.subst(iop) 22510785Sgope@wisc.edu decode_block = BasicDecode.subst(iop) 22610785Sgope@wisc.edu exec_output = ThreadRegisterExecute.subst(iop) 22710785Sgope@wisc.edu}}; 22810785Sgope@wisc.edu