util.isa revision 2706
17199Sgblack@eecs.umich.edu// -*- mode:c++ -*- 27199Sgblack@eecs.umich.edu 37199Sgblack@eecs.umich.edu// Copyright (c) 2003-2006 The Regents of The University of Michigan 47199Sgblack@eecs.umich.edu// All rights reserved. 57199Sgblack@eecs.umich.edu// 67199Sgblack@eecs.umich.edu// Redistribution and use in source and binary forms, with or without 77199Sgblack@eecs.umich.edu// modification, are permitted provided that the following conditions are 87199Sgblack@eecs.umich.edu// met: redistributions of source code must retain the above copyright 97199Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer; 107199Sgblack@eecs.umich.edu// redistributions in binary form must reproduce the above copyright 117199Sgblack@eecs.umich.edu// notice, this list of conditions and the following disclaimer in the 127199Sgblack@eecs.umich.edu// documentation and/or other materials provided with the distribution; 137199Sgblack@eecs.umich.edu// neither the name of the copyright holders nor the names of its 147199Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from 157199Sgblack@eecs.umich.edu// this software without specific prior written permission. 167199Sgblack@eecs.umich.edu// 177199Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 187199Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 197199Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 207199Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 217199Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 227199Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 237199Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 247199Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 257199Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 267199Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 277199Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 287199Sgblack@eecs.umich.edu// 297199Sgblack@eecs.umich.edu// Authors: Steve Reinhardt 307199Sgblack@eecs.umich.edu// Korey Sewell 317199Sgblack@eecs.umich.edu 327199Sgblack@eecs.umich.edulet {{ 337199Sgblack@eecs.umich.edudef LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 347199Sgblack@eecs.umich.edu postacc_code = '', base_class = 'Memory', 357199Sgblack@eecs.umich.edu decode_template = BasicDecode, exec_template_base = ''): 367199Sgblack@eecs.umich.edu # Make sure flags are in lists (convert to lists if not). 377199Sgblack@eecs.umich.edu mem_flags = makeList(mem_flags) 387199Sgblack@eecs.umich.edu inst_flags = makeList(inst_flags) 397199Sgblack@eecs.umich.edu 407199Sgblack@eecs.umich.edu # add hook to get effective addresses into execution trace output. 417199Sgblack@eecs.umich.edu ea_code += '\nif (traceData) { traceData->setAddr(EA); }\n' 427199Sgblack@eecs.umich.edu 437199Sgblack@eecs.umich.edu # generate code block objects 447199Sgblack@eecs.umich.edu ea_cblk = CodeBlock(ea_code) 457199Sgblack@eecs.umich.edu memacc_cblk = CodeBlock(memacc_code) 467199Sgblack@eecs.umich.edu postacc_cblk = CodeBlock(postacc_code) 477199Sgblack@eecs.umich.edu 487199Sgblack@eecs.umich.edu # Some CPU models execute the memory operation as an atomic unit, 497199Sgblack@eecs.umich.edu # while others want to separate them into an effective address 507199Sgblack@eecs.umich.edu # computation and a memory access operation. As a result, we need 517199Sgblack@eecs.umich.edu # to generate three StaticInst objects. Note that the latter two 527199Sgblack@eecs.umich.edu # are nested inside the larger "atomic" one. 537199Sgblack@eecs.umich.edu 547199Sgblack@eecs.umich.edu # generate InstObjParams for EAComp object 557199Sgblack@eecs.umich.edu ea_iop = InstObjParams(name, Name, base_class, ea_cblk, inst_flags) 567199Sgblack@eecs.umich.edu 577199Sgblack@eecs.umich.edu # generate InstObjParams for MemAcc object 587202Sgblack@eecs.umich.edu memacc_iop = InstObjParams(name, Name, base_class, memacc_cblk, inst_flags) 597202Sgblack@eecs.umich.edu # in the split execution model, the MemAcc portion is responsible 607202Sgblack@eecs.umich.edu # for the post-access code. 617202Sgblack@eecs.umich.edu memacc_iop.postacc_code = postacc_cblk.code 627202Sgblack@eecs.umich.edu 637202Sgblack@eecs.umich.edu # generate InstObjParams for InitiateAcc, CompleteAcc object 647202Sgblack@eecs.umich.edu # The code used depends on the template being used 657202Sgblack@eecs.umich.edu if (exec_template_base == 'Load'): 667599Sminkyu.jeong@arm.com initiateacc_cblk = CodeBlock(ea_code + memacc_code) 677783SGiacomo.Gabrielli@arm.com completeacc_cblk = CodeBlock(memacc_code + postacc_code) 687202Sgblack@eecs.umich.edu elif (exec_template_base == 'Store'): 697202Sgblack@eecs.umich.edu initiateacc_cblk = CodeBlock(ea_code + memacc_code) 707202Sgblack@eecs.umich.edu completeacc_cblk = CodeBlock(postacc_code) 717202Sgblack@eecs.umich.edu else: 727202Sgblack@eecs.umich.edu initiateacc_cblk = '' 737202Sgblack@eecs.umich.edu completeacc_cblk = '' 747202Sgblack@eecs.umich.edu 757599Sminkyu.jeong@arm.com initiateacc_iop = InstObjParams(name, Name, base_class, initiateacc_cblk, 767783SGiacomo.Gabrielli@arm.com inst_flags) 777202Sgblack@eecs.umich.edu 787202Sgblack@eecs.umich.edu completeacc_iop = InstObjParams(name, Name, base_class, completeacc_cblk, 797202Sgblack@eecs.umich.edu inst_flags) 807202Sgblack@eecs.umich.edu 817202Sgblack@eecs.umich.edu if (exec_template_base == 'Load'): 827400SAli.Saidi@ARM.com initiateacc_iop.ea_code = ea_cblk.code 837202Sgblack@eecs.umich.edu initiateacc_iop.memacc_code = memacc_cblk.code 847400SAli.Saidi@ARM.com completeacc_iop.memacc_code = memacc_cblk.code 857202Sgblack@eecs.umich.edu completeacc_iop.postacc_code = postacc_cblk.code 867797Sgblack@eecs.umich.edu elif (exec_template_base == 'Store'): 877797Sgblack@eecs.umich.edu initiateacc_iop.ea_code = ea_cblk.code 887858SMatt.Horsnell@arm.com initiateacc_iop.memacc_code = memacc_cblk.code 897858SMatt.Horsnell@arm.com completeacc_iop.postacc_code = postacc_cblk.code 907202Sgblack@eecs.umich.edu 917202Sgblack@eecs.umich.edu # generate InstObjParams for unified execution 927202Sgblack@eecs.umich.edu cblk = CodeBlock(ea_code + memacc_code + postacc_code) 937202Sgblack@eecs.umich.edu iop = InstObjParams(name, Name, base_class, cblk, inst_flags) 947599Sminkyu.jeong@arm.com 957599Sminkyu.jeong@arm.com iop.ea_constructor = ea_cblk.constructor 967202Sgblack@eecs.umich.edu iop.ea_code = ea_cblk.code 977202Sgblack@eecs.umich.edu iop.memacc_constructor = memacc_cblk.constructor 987202Sgblack@eecs.umich.edu iop.memacc_code = memacc_cblk.code 997202Sgblack@eecs.umich.edu iop.postacc_code = postacc_cblk.code 1007202Sgblack@eecs.umich.edu 1017202Sgblack@eecs.umich.edu if mem_flags: 1027202Sgblack@eecs.umich.edu s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';' 1037599Sminkyu.jeong@arm.com iop.constructor += s 1047599Sminkyu.jeong@arm.com memacc_iop.constructor += s 1057202Sgblack@eecs.umich.edu 1067202Sgblack@eecs.umich.edu # select templates 1077202Sgblack@eecs.umich.edu memAccExecTemplate = eval(exec_template_base + 'MemAccExecute') 1087202Sgblack@eecs.umich.edu fullExecTemplate = eval(exec_template_base + 'Execute') 1097202Sgblack@eecs.umich.edu initiateAccTemplate = eval(exec_template_base + 'InitiateAcc') 1107400SAli.Saidi@ARM.com completeAccTemplate = eval(exec_template_base + 'CompleteAcc') 1117202Sgblack@eecs.umich.edu 1127400SAli.Saidi@ARM.com # (header_output, decoder_output, decode_block, exec_output) 1137202Sgblack@eecs.umich.edu return (LoadStoreDeclare.subst(iop), LoadStoreConstructor.subst(iop), 1147797Sgblack@eecs.umich.edu decode_template.subst(iop), 1157797Sgblack@eecs.umich.edu EACompExecute.subst(ea_iop) 1167858SMatt.Horsnell@arm.com + memAccExecTemplate.subst(memacc_iop) 1177858SMatt.Horsnell@arm.com + fullExecTemplate.subst(iop) 1187202Sgblack@eecs.umich.edu + initiateAccTemplate.subst(initiateacc_iop) 1197202Sgblack@eecs.umich.edu + completeAccTemplate.subst(completeacc_iop)) 1207202Sgblack@eecs.umich.edu}}; 1217202Sgblack@eecs.umich.edu 1227599Sminkyu.jeong@arm.comoutput header {{ 1237599Sminkyu.jeong@arm.com std::string inst2string(MachInst machInst); 1247202Sgblack@eecs.umich.edu}}; 1257202Sgblack@eecs.umich.edu 1267202Sgblack@eecs.umich.eduoutput decoder {{ 1277202Sgblack@eecs.umich.edu 1287202Sgblack@eecs.umich.edustd::string inst2string(MachInst machInst) 1297202Sgblack@eecs.umich.edu{ 1307202Sgblack@eecs.umich.edu string str = ""; 1317599Sminkyu.jeong@arm.com uint32_t mask = 0x80000000; 1327599Sminkyu.jeong@arm.com 1337202Sgblack@eecs.umich.edu for(int i=0; i < 32; i++) { 1347202Sgblack@eecs.umich.edu if ((machInst & mask) == 0) { 1357202Sgblack@eecs.umich.edu str += "0"; 1367209Sgblack@eecs.umich.edu } else { 1377209Sgblack@eecs.umich.edu str += "1"; 1387209Sgblack@eecs.umich.edu } 1397209Sgblack@eecs.umich.edu 1407209Sgblack@eecs.umich.edu mask = mask >> 1; 1417261Sgblack@eecs.umich.edu } 1427209Sgblack@eecs.umich.edu 1437209Sgblack@eecs.umich.edu return str; 1447261Sgblack@eecs.umich.edu} 1457261Sgblack@eecs.umich.edu 1467209Sgblack@eecs.umich.edu}}; 1477209Sgblack@eecs.umich.eduoutput exec {{ 1487209Sgblack@eecs.umich.edu 1497209Sgblack@eecs.umich.edu using namespace MipsISA; 1507209Sgblack@eecs.umich.edu 1517209Sgblack@eecs.umich.edu /// CLEAR ALL CPU INST/EXE HAZARDS 1527209Sgblack@eecs.umich.edu inline void 1537209Sgblack@eecs.umich.edu clear_exe_inst_hazards() 1547209Sgblack@eecs.umich.edu { 1557261Sgblack@eecs.umich.edu //CODE HERE 1567209Sgblack@eecs.umich.edu } 1577209Sgblack@eecs.umich.edu 1587261Sgblack@eecs.umich.edu 1597261Sgblack@eecs.umich.edu /// Check "FP enabled" machine status bit. Called when executing any FP 1607209Sgblack@eecs.umich.edu /// instruction in full-system mode. 1617209Sgblack@eecs.umich.edu /// @retval Full-system mode: NoFault if FP is enabled, FenFault 1627209Sgblack@eecs.umich.edu /// if not. Non-full-system mode: always returns NoFault. 1637209Sgblack@eecs.umich.edu#if FULL_SYSTEM 1647209Sgblack@eecs.umich.edu inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc) 1657209Sgblack@eecs.umich.edu { 1667261Sgblack@eecs.umich.edu Fault fault = NoFault; // dummy... this ipr access should not fault 1677209Sgblack@eecs.umich.edu if (!Mips34k::ICSR_FPE(xc->readIpr(MipsISA::IPR_ICSR, fault))) { 1687209Sgblack@eecs.umich.edu fault = FloatEnableFault; 1697261Sgblack@eecs.umich.edu } 1707261Sgblack@eecs.umich.edu return fault; 1717209Sgblack@eecs.umich.edu } 1727226Sgblack@eecs.umich.edu#else 1737249Sgblack@eecs.umich.edu inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc) 1747249Sgblack@eecs.umich.edu { 1757249Sgblack@eecs.umich.edu return NoFault; 1767249Sgblack@eecs.umich.edu } 1777249Sgblack@eecs.umich.edu#endif 1787249Sgblack@eecs.umich.edu 1797249Sgblack@eecs.umich.edu 1807249Sgblack@eecs.umich.edu 1817249Sgblack@eecs.umich.edu}}; 1827249Sgblack@eecs.umich.edu 1837249Sgblack@eecs.umich.edu 1847249Sgblack@eecs.umich.edu