util.isa revision 2754
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)
682124SN/A    elif (exec_template_base == '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
862124SN/A    elif (exec_template_base == '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
1072124SN/A    memAccExecTemplate = eval(exec_template_base + 'MemAccExecute')
1082124SN/A    fullExecTemplate = eval(exec_template_base + 'Execute')
1092124SN/A    initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
1102124SN/A    completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
1112124SN/A
1122124SN/A    # (header_output, decoder_output, decode_block, exec_output)
1132124SN/A    return (LoadStoreDeclare.subst(iop), LoadStoreConstructor.subst(iop),
1142124SN/A            decode_template.subst(iop),
1152124SN/A            EACompExecute.subst(ea_iop)
1162124SN/A            + memAccExecTemplate.subst(memacc_iop)
1172124SN/A            + fullExecTemplate.subst(iop)
1182124SN/A            + initiateAccTemplate.subst(initiateacc_iop)
1192124SN/A            + completeAccTemplate.subst(completeacc_iop))
1202100SN/A}};
1212123SN/A
1222686Sksewell@umich.eduoutput header {{
1232686Sksewell@umich.edu        std::string inst2string(MachInst machInst);
1242686Sksewell@umich.edu}};
1252124SN/A
1262686Sksewell@umich.eduoutput decoder {{
1272686Sksewell@umich.edu
1282686Sksewell@umich.edustd::string inst2string(MachInst machInst)
1292686Sksewell@umich.edu{
1302686Sksewell@umich.edu    string str = "";
1312686Sksewell@umich.edu    uint32_t mask = 0x80000000;
1322686Sksewell@umich.edu
1332686Sksewell@umich.edu    for(int i=0; i < 32; i++) {
1342686Sksewell@umich.edu        if ((machInst & mask) == 0) {
1352686Sksewell@umich.edu            str += "0";
1362686Sksewell@umich.edu        } else {
1372686Sksewell@umich.edu            str += "1";
1382686Sksewell@umich.edu        }
1392686Sksewell@umich.edu
1402686Sksewell@umich.edu        mask = mask >> 1;
1412686Sksewell@umich.edu    }
1422686Sksewell@umich.edu
1432686Sksewell@umich.edu    return str;
1442686Sksewell@umich.edu}
1452686Sksewell@umich.edu
1462686Sksewell@umich.edu}};
1472123SN/Aoutput exec {{
1482123SN/A
1492550SN/A    using namespace MipsISA;
1502550SN/A
1512123SN/A    /// CLEAR ALL CPU INST/EXE HAZARDS
1522123SN/A    inline void
1532123SN/A    clear_exe_inst_hazards()
1542123SN/A    {
1552123SN/A        //CODE HERE
1562123SN/A    }
1572239SN/A
1582239SN/A
1592239SN/A    /// Check "FP enabled" machine status bit.  Called when executing any FP
1602239SN/A    /// instruction in full-system mode.
1612239SN/A    /// @retval Full-system mode: NoFault if FP is enabled, FenFault
1622239SN/A    /// if not.  Non-full-system mode: always returns NoFault.
1632239SN/A#if FULL_SYSTEM
1642239SN/A    inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc)
1652239SN/A    {
1662239SN/A        Fault fault = NoFault;	// dummy... this ipr access should not fault
1672239SN/A        if (!Mips34k::ICSR_FPE(xc->readIpr(MipsISA::IPR_ICSR, fault))) {
1682239SN/A            fault = FloatEnableFault;
1692239SN/A        }
1702239SN/A        return fault;
1712239SN/A    }
1722239SN/A#else
1732239SN/A    inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc)
1742239SN/A    {
1752239SN/A        return NoFault;
1762239SN/A    }
1772239SN/A#endif
1782239SN/A
1792239SN/A
1802686Sksewell@umich.edu
1812135SN/A}};
1822239SN/A
1832239SN/A
184