util.isa revision 2935
12100SN/A// -*- mode:c++ -*- 22100SN/A 32754Sksewell@umich.edu// Copyright (c) 2006 The Regents of The University of Michigan 42706Sksewell@umich.edu// All rights reserved. 52706Sksewell@umich.edu// 62706Sksewell@umich.edu// Redistribution and use in source and binary forms, with or without 72706Sksewell@umich.edu// modification, are permitted provided that the following conditions are 82706Sksewell@umich.edu// met: redistributions of source code must retain the above copyright 92706Sksewell@umich.edu// notice, this list of conditions and the following disclaimer; 102706Sksewell@umich.edu// redistributions in binary form must reproduce the above copyright 112706Sksewell@umich.edu// notice, this list of conditions and the following disclaimer in the 122706Sksewell@umich.edu// documentation and/or other materials provided with the distribution; 132706Sksewell@umich.edu// neither the name of the copyright holders nor the names of its 142706Sksewell@umich.edu// contributors may be used to endorse or promote products derived from 152706Sksewell@umich.edu// this software without specific prior written permission. 162706Sksewell@umich.edu// 172706Sksewell@umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182706Sksewell@umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192706Sksewell@umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202706Sksewell@umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212706Sksewell@umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222706Sksewell@umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232706Sksewell@umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242706Sksewell@umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252706Sksewell@umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262706Sksewell@umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272706Sksewell@umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282706Sksewell@umich.edu// 292706Sksewell@umich.edu// Authors: Steve Reinhardt 302706Sksewell@umich.edu// Korey Sewell 312706Sksewell@umich.edu 322100SN/Alet {{ 332124SN/Adef LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 342124SN/A postacc_code = '', base_class = 'Memory', 352124SN/A decode_template = BasicDecode, exec_template_base = ''): 362124SN/A # Make sure flags are in lists (convert to lists if not). 372124SN/A mem_flags = makeList(mem_flags) 382124SN/A inst_flags = makeList(inst_flags) 392124SN/A 402124SN/A # add hook to get effective addresses into execution trace output. 412124SN/A ea_code += '\nif (traceData) { traceData->setAddr(EA); }\n' 422124SN/A 432124SN/A # generate code block objects 442124SN/A ea_cblk = CodeBlock(ea_code) 452124SN/A memacc_cblk = CodeBlock(memacc_code) 462124SN/A postacc_cblk = CodeBlock(postacc_code) 472124SN/A 482124SN/A # Some CPU models execute the memory operation as an atomic unit, 492124SN/A # while others want to separate them into an effective address 502124SN/A # computation and a memory access operation. As a result, we need 512124SN/A # to generate three StaticInst objects. Note that the latter two 522124SN/A # are nested inside the larger "atomic" one. 532124SN/A 542124SN/A # generate InstObjParams for EAComp object 552124SN/A ea_iop = InstObjParams(name, Name, base_class, ea_cblk, inst_flags) 562124SN/A 572124SN/A # generate InstObjParams for MemAcc object 582124SN/A memacc_iop = InstObjParams(name, Name, base_class, memacc_cblk, inst_flags) 592124SN/A # in the split execution model, the MemAcc portion is responsible 602124SN/A # for the post-access code. 612124SN/A memacc_iop.postacc_code = postacc_cblk.code 622124SN/A 632124SN/A # generate InstObjParams for InitiateAcc, CompleteAcc object 642124SN/A # The code used depends on the template being used 652124SN/A if (exec_template_base == 'Load'): 662124SN/A initiateacc_cblk = CodeBlock(ea_code + memacc_code) 672124SN/A completeacc_cblk = CodeBlock(memacc_code + postacc_code) 682935Sksewell@umich.edu elif (exec_template_base.startswith('Store')): 692124SN/A initiateacc_cblk = CodeBlock(ea_code + memacc_code) 702124SN/A completeacc_cblk = CodeBlock(postacc_code) 712124SN/A else: 722124SN/A initiateacc_cblk = '' 732124SN/A completeacc_cblk = '' 742124SN/A 752124SN/A initiateacc_iop = InstObjParams(name, Name, base_class, initiateacc_cblk, 762124SN/A inst_flags) 772124SN/A 782124SN/A completeacc_iop = InstObjParams(name, Name, base_class, completeacc_cblk, 792124SN/A inst_flags) 802124SN/A 812124SN/A if (exec_template_base == 'Load'): 822124SN/A initiateacc_iop.ea_code = ea_cblk.code 832124SN/A initiateacc_iop.memacc_code = memacc_cblk.code 842124SN/A completeacc_iop.memacc_code = memacc_cblk.code 852124SN/A completeacc_iop.postacc_code = postacc_cblk.code 862935Sksewell@umich.edu elif (exec_template_base.startswith('Store')): 872124SN/A initiateacc_iop.ea_code = ea_cblk.code 882124SN/A initiateacc_iop.memacc_code = memacc_cblk.code 892124SN/A completeacc_iop.postacc_code = postacc_cblk.code 902124SN/A 912124SN/A # generate InstObjParams for unified execution 922124SN/A cblk = CodeBlock(ea_code + memacc_code + postacc_code) 932124SN/A iop = InstObjParams(name, Name, base_class, cblk, inst_flags) 942124SN/A 952124SN/A iop.ea_constructor = ea_cblk.constructor 962124SN/A iop.ea_code = ea_cblk.code 972124SN/A iop.memacc_constructor = memacc_cblk.constructor 982124SN/A iop.memacc_code = memacc_cblk.code 992124SN/A iop.postacc_code = postacc_cblk.code 1002124SN/A 1012124SN/A if mem_flags: 1022124SN/A s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';' 1032124SN/A iop.constructor += s 1042124SN/A memacc_iop.constructor += s 1052124SN/A 1062124SN/A # select templates 1072935Sksewell@umich.edu 1082935Sksewell@umich.edu # define aliases... most StoreCond templates are the same as the 1092935Sksewell@umich.edu # corresponding Store templates (only CompleteAcc is different). 1102935Sksewell@umich.edu StoreCondMemAccExecute = StoreMemAccExecute 1112935Sksewell@umich.edu StoreCondExecute = StoreExecute 1122935Sksewell@umich.edu StoreCondInitiateAcc = StoreInitiateAcc 1132935Sksewell@umich.edu 1142124SN/A memAccExecTemplate = eval(exec_template_base + 'MemAccExecute') 1152124SN/A fullExecTemplate = eval(exec_template_base + 'Execute') 1162124SN/A initiateAccTemplate = eval(exec_template_base + 'InitiateAcc') 1172124SN/A completeAccTemplate = eval(exec_template_base + 'CompleteAcc') 1182124SN/A 1192124SN/A # (header_output, decoder_output, decode_block, exec_output) 1202124SN/A return (LoadStoreDeclare.subst(iop), LoadStoreConstructor.subst(iop), 1212124SN/A decode_template.subst(iop), 1222124SN/A EACompExecute.subst(ea_iop) 1232124SN/A + memAccExecTemplate.subst(memacc_iop) 1242124SN/A + fullExecTemplate.subst(iop) 1252124SN/A + initiateAccTemplate.subst(initiateacc_iop) 1262124SN/A + completeAccTemplate.subst(completeacc_iop)) 1272100SN/A}}; 1282686Sksewell@umich.eduoutput header {{ 1292686Sksewell@umich.edu std::string inst2string(MachInst machInst); 1302686Sksewell@umich.edu}}; 1312124SN/A 1322686Sksewell@umich.eduoutput decoder {{ 1332686Sksewell@umich.edu 1342686Sksewell@umich.edustd::string inst2string(MachInst machInst) 1352686Sksewell@umich.edu{ 1362686Sksewell@umich.edu string str = ""; 1372686Sksewell@umich.edu uint32_t mask = 0x80000000; 1382686Sksewell@umich.edu 1392686Sksewell@umich.edu for(int i=0; i < 32; i++) { 1402686Sksewell@umich.edu if ((machInst & mask) == 0) { 1412686Sksewell@umich.edu str += "0"; 1422686Sksewell@umich.edu } else { 1432686Sksewell@umich.edu str += "1"; 1442686Sksewell@umich.edu } 1452686Sksewell@umich.edu 1462686Sksewell@umich.edu mask = mask >> 1; 1472686Sksewell@umich.edu } 1482686Sksewell@umich.edu 1492686Sksewell@umich.edu return str; 1502686Sksewell@umich.edu} 1512686Sksewell@umich.edu 1522686Sksewell@umich.edu}}; 1532123SN/Aoutput exec {{ 1542123SN/A 1552550SN/A using namespace MipsISA; 1562550SN/A 1572123SN/A /// CLEAR ALL CPU INST/EXE HAZARDS 1582123SN/A inline void 1592123SN/A clear_exe_inst_hazards() 1602123SN/A { 1612123SN/A //CODE HERE 1622123SN/A } 1632239SN/A 1642239SN/A 1652239SN/A /// Check "FP enabled" machine status bit. Called when executing any FP 1662239SN/A /// instruction in full-system mode. 1672239SN/A /// @retval Full-system mode: NoFault if FP is enabled, FenFault 1682239SN/A /// if not. Non-full-system mode: always returns NoFault. 1692239SN/A#if FULL_SYSTEM 1702239SN/A inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc) 1712239SN/A { 1722239SN/A Fault fault = NoFault; // dummy... this ipr access should not fault 1732239SN/A if (!Mips34k::ICSR_FPE(xc->readIpr(MipsISA::IPR_ICSR, fault))) { 1742239SN/A fault = FloatEnableFault; 1752239SN/A } 1762239SN/A return fault; 1772239SN/A } 1782239SN/A#else 1792239SN/A inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc) 1802239SN/A { 1812239SN/A return NoFault; 1822239SN/A } 1832239SN/A#endif 1842239SN/A 1852239SN/A 1862686Sksewell@umich.edu 1872135SN/A}}; 1882239SN/A 1892239SN/A 190