util.isa revision 2686
12100SN/A// -*- mode:c++ -*-
22100SN/A
32100SN/Alet {{
42124SN/Adef LoadStoreBase(name, Name, ea_code, memacc_code, mem_flags, inst_flags,
52124SN/A                  postacc_code = '', base_class = 'Memory',
62124SN/A                  decode_template = BasicDecode, exec_template_base = ''):
72124SN/A    # Make sure flags are in lists (convert to lists if not).
82124SN/A    mem_flags = makeList(mem_flags)
92124SN/A    inst_flags = makeList(inst_flags)
102124SN/A
112124SN/A    # add hook to get effective addresses into execution trace output.
122124SN/A    ea_code += '\nif (traceData) { traceData->setAddr(EA); }\n'
132124SN/A
142124SN/A    # generate code block objects
152124SN/A    ea_cblk = CodeBlock(ea_code)
162124SN/A    memacc_cblk = CodeBlock(memacc_code)
172124SN/A    postacc_cblk = CodeBlock(postacc_code)
182124SN/A
192124SN/A    # Some CPU models execute the memory operation as an atomic unit,
202124SN/A    # while others want to separate them into an effective address
212124SN/A    # computation and a memory access operation.  As a result, we need
222124SN/A    # to generate three StaticInst objects.  Note that the latter two
232124SN/A    # are nested inside the larger "atomic" one.
242124SN/A
252124SN/A    # generate InstObjParams for EAComp object
262124SN/A    ea_iop = InstObjParams(name, Name, base_class, ea_cblk, inst_flags)
272124SN/A
282124SN/A    # generate InstObjParams for MemAcc object
292124SN/A    memacc_iop = InstObjParams(name, Name, base_class, memacc_cblk, inst_flags)
302124SN/A    # in the split execution model, the MemAcc portion is responsible
312124SN/A    # for the post-access code.
322124SN/A    memacc_iop.postacc_code = postacc_cblk.code
332124SN/A
342124SN/A    # generate InstObjParams for InitiateAcc, CompleteAcc object
352124SN/A    # The code used depends on the template being used
362124SN/A    if (exec_template_base == 'Load'):
372124SN/A        initiateacc_cblk = CodeBlock(ea_code + memacc_code)
382124SN/A        completeacc_cblk = CodeBlock(memacc_code + postacc_code)
392124SN/A    elif (exec_template_base == 'Store'):
402124SN/A        initiateacc_cblk = CodeBlock(ea_code + memacc_code)
412124SN/A        completeacc_cblk = CodeBlock(postacc_code)
422124SN/A    else:
432124SN/A        initiateacc_cblk = ''
442124SN/A        completeacc_cblk = ''
452124SN/A
462124SN/A    initiateacc_iop = InstObjParams(name, Name, base_class, initiateacc_cblk,
472124SN/A                                    inst_flags)
482124SN/A
492124SN/A    completeacc_iop = InstObjParams(name, Name, base_class, completeacc_cblk,
502124SN/A                                    inst_flags)
512124SN/A
522124SN/A    if (exec_template_base == 'Load'):
532124SN/A        initiateacc_iop.ea_code = ea_cblk.code
542124SN/A        initiateacc_iop.memacc_code = memacc_cblk.code
552124SN/A        completeacc_iop.memacc_code = memacc_cblk.code
562124SN/A        completeacc_iop.postacc_code = postacc_cblk.code
572124SN/A    elif (exec_template_base == 'Store'):
582124SN/A        initiateacc_iop.ea_code = ea_cblk.code
592124SN/A        initiateacc_iop.memacc_code = memacc_cblk.code
602124SN/A        completeacc_iop.postacc_code = postacc_cblk.code
612124SN/A
622124SN/A    # generate InstObjParams for unified execution
632124SN/A    cblk = CodeBlock(ea_code + memacc_code + postacc_code)
642124SN/A    iop = InstObjParams(name, Name, base_class, cblk, inst_flags)
652124SN/A
662124SN/A    iop.ea_constructor = ea_cblk.constructor
672124SN/A    iop.ea_code = ea_cblk.code
682124SN/A    iop.memacc_constructor = memacc_cblk.constructor
692124SN/A    iop.memacc_code = memacc_cblk.code
702124SN/A    iop.postacc_code = postacc_cblk.code
712124SN/A
722124SN/A    if mem_flags:
732124SN/A        s = '\n\tmemAccessFlags = ' + string.join(mem_flags, '|') + ';'
742124SN/A        iop.constructor += s
752124SN/A        memacc_iop.constructor += s
762124SN/A
772124SN/A    # select templates
782124SN/A    memAccExecTemplate = eval(exec_template_base + 'MemAccExecute')
792124SN/A    fullExecTemplate = eval(exec_template_base + 'Execute')
802124SN/A    initiateAccTemplate = eval(exec_template_base + 'InitiateAcc')
812124SN/A    completeAccTemplate = eval(exec_template_base + 'CompleteAcc')
822124SN/A
832124SN/A    # (header_output, decoder_output, decode_block, exec_output)
842124SN/A    return (LoadStoreDeclare.subst(iop), LoadStoreConstructor.subst(iop),
852124SN/A            decode_template.subst(iop),
862124SN/A            EACompExecute.subst(ea_iop)
872124SN/A            + memAccExecTemplate.subst(memacc_iop)
882124SN/A            + fullExecTemplate.subst(iop)
892124SN/A            + initiateAccTemplate.subst(initiateacc_iop)
902124SN/A            + completeAccTemplate.subst(completeacc_iop))
912100SN/A}};
922123SN/A
932686Sksewell@umich.eduoutput header {{
942686Sksewell@umich.edu        std::string inst2string(MachInst machInst);
952686Sksewell@umich.edu}};
962124SN/A
972686Sksewell@umich.eduoutput decoder {{
982686Sksewell@umich.edu
992686Sksewell@umich.edustd::string inst2string(MachInst machInst)
1002686Sksewell@umich.edu{
1012686Sksewell@umich.edu    string str = "";
1022686Sksewell@umich.edu    uint32_t mask = 0x80000000;
1032686Sksewell@umich.edu
1042686Sksewell@umich.edu    for(int i=0; i < 32; i++) {
1052686Sksewell@umich.edu        if ((machInst & mask) == 0) {
1062686Sksewell@umich.edu            str += "0";
1072686Sksewell@umich.edu        } else {
1082686Sksewell@umich.edu            str += "1";
1092686Sksewell@umich.edu        }
1102686Sksewell@umich.edu
1112686Sksewell@umich.edu        mask = mask >> 1;
1122686Sksewell@umich.edu    }
1132686Sksewell@umich.edu
1142686Sksewell@umich.edu    return str;
1152686Sksewell@umich.edu}
1162686Sksewell@umich.edu
1172686Sksewell@umich.edu}};
1182123SN/Aoutput exec {{
1192123SN/A
1202550SN/A    using namespace MipsISA;
1212550SN/A
1222123SN/A    /// CLEAR ALL CPU INST/EXE HAZARDS
1232123SN/A    inline void
1242123SN/A    clear_exe_inst_hazards()
1252123SN/A    {
1262123SN/A        //CODE HERE
1272123SN/A    }
1282239SN/A
1292239SN/A
1302239SN/A    /// Check "FP enabled" machine status bit.  Called when executing any FP
1312239SN/A    /// instruction in full-system mode.
1322239SN/A    /// @retval Full-system mode: NoFault if FP is enabled, FenFault
1332239SN/A    /// if not.  Non-full-system mode: always returns NoFault.
1342239SN/A#if FULL_SYSTEM
1352239SN/A    inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc)
1362239SN/A    {
1372239SN/A        Fault fault = NoFault;	// dummy... this ipr access should not fault
1382239SN/A        if (!Mips34k::ICSR_FPE(xc->readIpr(MipsISA::IPR_ICSR, fault))) {
1392239SN/A            fault = FloatEnableFault;
1402239SN/A        }
1412239SN/A        return fault;
1422239SN/A    }
1432239SN/A#else
1442239SN/A    inline Fault checkFpEnableFault(%(CPU_exec_context)s *xc)
1452239SN/A    {
1462239SN/A        return NoFault;
1472239SN/A    }
1482239SN/A#endif
1492239SN/A
1502239SN/A
1512686Sksewell@umich.edu
1522135SN/A}};
1532239SN/A
1542239SN/A
155