util.isa revision 5736
12100SN/A// -*- mode:c++ -*- 22100SN/A 35268Sksewell@umich.edu// Copyright (c) 2003-2005 The Regents of The University of Michigan 45268Sksewell@umich.edu// Copyright (c) 2007 MIPS Technologies, Inc. 55268Sksewell@umich.edu// All rights reserved. 65268Sksewell@umich.edu// 75268Sksewell@umich.edu// Redistribution and use in source and binary forms, with or without 85268Sksewell@umich.edu// modification, are permitted provided that the following conditions are 95268Sksewell@umich.edu// met: redistributions of source code must retain the above copyright 105268Sksewell@umich.edu// notice, this list of conditions and the following disclaimer; 115268Sksewell@umich.edu// redistributions in binary form must reproduce the above copyright 125268Sksewell@umich.edu// notice, this list of conditions and the following disclaimer in the 135268Sksewell@umich.edu// documentation and/or other materials provided with the distribution; 145268Sksewell@umich.edu// neither the name of the copyright holders nor the names of its 155268Sksewell@umich.edu// contributors may be used to endorse or promote products derived from 165268Sksewell@umich.edu// this software without specific prior written permission. 175268Sksewell@umich.edu// 185268Sksewell@umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 195268Sksewell@umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 205268Sksewell@umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 215268Sksewell@umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 225268Sksewell@umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 235268Sksewell@umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 245268Sksewell@umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 255268Sksewell@umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 265268Sksewell@umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 275268Sksewell@umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 285268Sksewell@umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 295268Sksewell@umich.edu// 305268Sksewell@umich.edu// Authors: Steve Reinhardt 315268Sksewell@umich.edu// Korey Sewell 322706Sksewell@umich.edu 332100SN/Alet {{ 342124SN/Adef LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags, 352124SN/A postacc_code = '', base_class = 'Memory', 362124SN/A decode_template = BasicDecode, exec_template_base = ''): 372124SN/A # Make sure flags are in lists (convert to lists if not). 382124SN/A mem_flags = makeList(mem_flags) 392124SN/A inst_flags = makeList(inst_flags) 402124SN/A 412124SN/A # add hook to get effective addresses into execution trace output. 422124SN/A ea_code += '\nif (traceData) { traceData->setAddr(EA); }\n' 432124SN/A 442124SN/A # Some CPU models execute the memory operation as an atomic unit, 452124SN/A # while others want to separate them into an effective address 462124SN/A # computation and a memory access operation. As a result, we need 472124SN/A # to generate three StaticInst objects. Note that the latter two 482124SN/A # are nested inside the larger "atomic" one. 492124SN/A 503953Sstever@eecs.umich.edu # Generate InstObjParams for each of the three objects. Note that 513953Sstever@eecs.umich.edu # they differ only in the set of code objects contained (which in 523953Sstever@eecs.umich.edu # turn affects the object's overall operand list). 533953Sstever@eecs.umich.edu iop = InstObjParams(name, Name, base_class, 543953Sstever@eecs.umich.edu { 'ea_code':ea_code, 'memacc_code':memacc_code, 'postacc_code':postacc_code }, 553953Sstever@eecs.umich.edu inst_flags) 563953Sstever@eecs.umich.edu ea_iop = InstObjParams(name, Name, base_class, 573953Sstever@eecs.umich.edu { 'ea_code':ea_code }, 583953Sstever@eecs.umich.edu inst_flags) 593953Sstever@eecs.umich.edu memacc_iop = InstObjParams(name, Name, base_class, 603953Sstever@eecs.umich.edu { 'memacc_code':memacc_code, 'postacc_code':postacc_code }, 613953Sstever@eecs.umich.edu inst_flags) 622124SN/A 632124SN/A if mem_flags: 645736Snate@binkert.org mem_flags = [ 'Request::%s' % flag for flag in mem_flags ] 655736Snate@binkert.org s = '\n\tmemAccessFlags.reset(' + string.join(mem_flags, '|') + ');' 662124SN/A iop.constructor += s 672124SN/A memacc_iop.constructor += s 682124SN/A 692124SN/A # select templates 702935Sksewell@umich.edu 714056Sstever@eecs.umich.edu # The InitiateAcc template is the same for StoreCond templates as the 724056Sstever@eecs.umich.edu # corresponding Store template.. 732935Sksewell@umich.edu StoreCondInitiateAcc = StoreInitiateAcc 742935Sksewell@umich.edu 752124SN/A memAccExecTemplate = eval(exec_template_base + 'MemAccExecute') 762124SN/A fullExecTemplate = eval(exec_template_base + 'Execute') 772124SN/A initiateAccTemplate = eval(exec_template_base + 'InitiateAcc') 782124SN/A completeAccTemplate = eval(exec_template_base + 'CompleteAcc') 795222Sksewell@umich.edu eaCompExecuteTemplate = eval('EACompExecute') 805222Sksewell@umich.edu 815222Sksewell@umich.edu if (exec_template_base == 'Load' or exec_template_base == 'Store'): 825222Sksewell@umich.edu memAccSizeTemplate = eval('LoadStoreMemAccSize') 835222Sksewell@umich.edu else: 845222Sksewell@umich.edu memAccSizeTemplate = eval('MiscMemAccSize') 852124SN/A 862124SN/A # (header_output, decoder_output, decode_block, exec_output) 873953Sstever@eecs.umich.edu return (LoadStoreDeclare.subst(iop), 883953Sstever@eecs.umich.edu EACompConstructor.subst(ea_iop) 893953Sstever@eecs.umich.edu + MemAccConstructor.subst(memacc_iop) 903953Sstever@eecs.umich.edu + LoadStoreConstructor.subst(iop), 912124SN/A decode_template.subst(iop), 925222Sksewell@umich.edu eaCompExecuteTemplate.subst(ea_iop) 932124SN/A + memAccExecTemplate.subst(memacc_iop) 942124SN/A + fullExecTemplate.subst(iop) 953953Sstever@eecs.umich.edu + initiateAccTemplate.subst(iop) 965222Sksewell@umich.edu + completeAccTemplate.subst(iop) 975222Sksewell@umich.edu + memAccSizeTemplate.subst(memacc_iop)) 982100SN/A}}; 993953Sstever@eecs.umich.edu 1002686Sksewell@umich.eduoutput header {{ 1012686Sksewell@umich.edu std::string inst2string(MachInst machInst); 1022686Sksewell@umich.edu}}; 1032124SN/A 1042686Sksewell@umich.eduoutput decoder {{ 1052686Sksewell@umich.edu 1062686Sksewell@umich.edustd::string inst2string(MachInst machInst) 1072686Sksewell@umich.edu{ 1084661Sksewell@umich.edu string str = ""; 1092686Sksewell@umich.edu uint32_t mask = 0x80000000; 1102686Sksewell@umich.edu 1112686Sksewell@umich.edu for(int i=0; i < 32; i++) { 1122686Sksewell@umich.edu if ((machInst & mask) == 0) { 1132686Sksewell@umich.edu str += "0"; 1142686Sksewell@umich.edu } else { 1152686Sksewell@umich.edu str += "1"; 1162686Sksewell@umich.edu } 1172686Sksewell@umich.edu 1182686Sksewell@umich.edu mask = mask >> 1; 1192686Sksewell@umich.edu } 1202686Sksewell@umich.edu 1212686Sksewell@umich.edu return str; 1222686Sksewell@umich.edu} 1232686Sksewell@umich.edu 1242686Sksewell@umich.edu}}; 125